yahooquery icon indicating copy to clipboard operation
yahooquery copied to clipboard

unclosed ssl.SSLSocket

Open odufb opened this issue 4 years ago • 3 comments
trafficstars

hi all, I am new at python programming. I just try to get data using history function and there is no problem if I dont use thread. If I try to use thread I get following errors.

"ResourceWarning: unclosed <ssl.SSLSocket fd=5084, family=AddressFamily.AF_INET, type=SocketKind.SOCK_STREAM, proto=0, .....>"

"Exception ignored in: <ssl.SSLSocket fd=5264, family=AddressFamily.AF_INET, type=SocketKind.SOCK_STREAM, proto=0, ...."

these errors/warnings dont effect my program but it is annoying to see a lot of unwanted text at console.

I try to get rid of these warnings by using warnings.simplefilter("ignore", ResourceWarning) statement but it is useless.

I am not sure is this a important issue but any help about this topic appreciated

odufb avatar Mar 05 '21 10:03 odufb

What version of python are you using?

dpguthrie avatar Mar 14 '21 13:03 dpguthrie

3.8.5 (default, Sep 3 2020, 21:29:08) [MSC v.1916 64 bit (AMD64)]

odufb avatar Mar 15 '21 05:03 odufb

This seems to be caused by the self.session initialized in the constructor not being close() when the instance of _YahooFinance in base.py is destroyed.

For example, instead of retrieving multiple tickers in a list at once, it occurs when you create a method that processes them one by one in a loop.

def get_info_of_specified_ticker(ticker):
    result_data = {}
    tickerinfo = Ticker(ticker)
    summary = tickerinfo.summary_detail[ticker]
    # Process to extract only desired information to result_data
    return result_data #### At this point the warning in the title occurs

What the user can do is to explicitly close() the session before the instance is destroyed.

    # Process to extract only desired information to result_data
    tickerinfo.session.close() #### Explicitly close() the session
    return result_data

Essentially, add a destructor to the _YahooFinance class in base.py and close() self.session in it. If you have other resources to deal with in your destructor, you should add those as well.

kunif avatar Mar 03 '23 23:03 kunif