Skip to content

Unclosed Session/SSLSocket #29

Description

@sky-coding

When I run the following python code with a debugger attached -

polygon_api = polygon.RESTClient()
response = polygon_api.stocks_equities_aggregates('AAPL', 30, 'minute', '2020-06-30', '2020-06-30')

I get a post-run warning from my debugger -

ResourceWarning: unclosed <ssl.SSLSocket type=SocketKind.SOCK_STREAM, raddr=('38.133.177.84', 443)>

But if I run -

polygon_api = polygon.RESTClient()
response = polygon_api.stocks_equities_aggregates('AAPL', 30, 'minute', '2020-06-30', '2020-06-30')
polygon_api._session.close()

The polygon client cleans up and my debugger is happy.

Looking into why this is, Session will only call its own close() from its __exit__ method, which is only called if the class is being used as a context manager (e.g. using with Session() as s: statement, as suggested by their docs) - and RESTClient is not using it in this manner, so close() is just never being called and resources are being left open.

No activity

Activity on this issue will appear here.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions