question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Python DeprecationWarning in Exchange.close()

See original GitHub issue
  • OS: macOS 11.2
  • Programming Language version: Python 3.9.1
  • CCXT version: ccxtpro==0.5.51

Reproduction steps

Run this script with python3 -W default script.py.

import asyncio

from ccxtpro import ftx


async def main() -> None:
    client = ftx()
    ticker = await client.watch_ticker("BTC-PERP")
    print(ticker)
    await client.close()

    print("Closing")

if __name__ == '__main__':
    asyncio.run(main())

Results

A DeprecationWarning is triggered:

.venv/bin/python -W default script.py
.venv/lib/python3.9/site-packages/ccxtpro/base/exchange.py:178: DeprecationWarning: The explicit passing of coroutine objects to asyncio.wait() is deprecated since Python 3.8, and scheduled for removal in Python 3.11.
  await asyncio.wait([client.close() for client in self.clients.values()], return_when=asyncio.ALL_COMPLETED)
{'symbol': 'BTC-PERP', 'timestamp': 1612340929250, 'datetime': '2021-02-03T08:28:49.250Z', 'high': None, 'low': None, 'bid': 36106.0, 'bidVolume': 0.0831, 'ask': 36107.0, 'askVolume': 18.6912, 'vwap': None, 'open': None, 'close': 36108.0, 'last': 36108.0, 'previousClose': None, 'change': None, 'percentage': None, 'average': None, 'baseVolume': None, 'quoteVolume': None, 'info': {'bid': 36106.0, 'ask': 36107.0, 'bidSize': 0.0831, 'askSize': 18.6912, 'last': 36108.0, 'time': 1612340929.2509072}}
Closing

Possible solution

The problem is in the Exchange.close() method.

Replacing asyncio.wait() with asyncio.gather() resolves the problem.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:2
  • Comments:10 (10 by maintainers)

github_iconTop GitHub Comments

2reactions
frosty00commented, Mar 23, 2021

@pietrodn I can confirm I am able to reproduce the bug, will need a bit more time to solve it

2reactions
pietrodncommented, Mar 20, 2021

Hello @kroitor, I just tested with ccxtpro==0.6.12, ccxt==1.43.82 and confirm that the original issue is gone. Thank you! 🚀

However I see another warning when executing the script with python -X dev (to enable all default warnings and asyncio debug mode).

I can open another issue though, it looks like a separate problem.

.venv/bin/python -W default -X dev "/Users/pd/Library/Application Support/JetBrains/PyCharm2020.3/scratches/scratch.py"
{'symbol': 'BTC-PERP', 'timestamp': 1616272962356, 'datetime': '2021-03-20T20:42:42.356Z', 'high': None, 'low': None, 'bid': 58439.0, 'bidVolume': 0.9143, 'ask': 58440.0, 'askVolume': 0.2803, 'vwap': None, 'open': None, 'close': 58440.0, 'last': 58440.0, 'previousClose': None, 'change': None, 'percentage': None, 'average': None, 'baseVolume': None, 'quoteVolume': None, 'info': {'bid': 58439.0, 'ask': 58440.0, 'bidSize': 0.9143, 'askSize': 0.2803, 'last': 58440.0, 'time': 1616272962.3567138}}
Closing
/Users/pd/.pyenv/versions/3.9.1/lib/python3.9/asyncio/selector_events.py:704: ResourceWarning: unclosed transport <_SelectorSocketTransport fd=7>
  _warn(f"unclosed transport {self!r}", ResourceWarning, source=self)
ResourceWarning: Enable tracemalloc to get the object allocation traceback
.venv/lib/python3.9/site-packages/aiohttp/client_reqrep.py:811: ResourceWarning: Unclosed response <ClientResponse(wss://ftx.com/ws) [101 Switching Protocols]>
<CIMultiDictProxy('Date': 'Sat, 20 Mar 2021 20:42:42 GMT', 'Connection': 'upgrade', 'Upgrade': 'websocket', REDACTED)>

  _warnings.warn(f"Unclosed response {self!r}", ResourceWarning, **kwargs)
ResourceWarning: Enable tracemalloc to get the object allocation traceback
Unclosed response
client_response: <ClientResponse(wss://ftx.com/ws) [101 Switching Protocols]>
<CIMultiDictProxy('Date': 'Sat, 20 Mar 2021 20:42:42 GMT', 'Connection': 'upgrade', 'Upgrade': 'websocket', REDACTED)>

source_traceback: Object created at (most recent call last):
  File "/Users/pd/Library/Application Support/JetBrains/PyCharm2020.3/scratches/scratch.py", line 15, in <module>
    asyncio.run(main())
  File "/Users/pd/.pyenv/versions/3.9.1/lib/python3.9/asyncio/runners.py", line 44, in run
    return loop.run_until_complete(main)
  File "/Users/pd/.pyenv/versions/3.9.1/lib/python3.9/asyncio/base_events.py", line 629, in run_until_complete
    self.run_forever()
  File "/Users/pd/.pyenv/versions/3.9.1/lib/python3.9/asyncio/base_events.py", line 596, in run_forever
    self._run_once()
  File "/Users/pd/.pyenv/versions/3.9.1/lib/python3.9/asyncio/base_events.py", line 1882, in _run_once
    handle._run()
  File "/Users/pd/.pyenv/versions/3.9.1/lib/python3.9/asyncio/events.py", line 80, in _run
    self._context.run(self._callback, *self._args)
  File ".venv/lib/python3.9/site-packages/aiohttp/client.py", line 1117, in __aenter__
    self._resp = await self._coro
  File ".venv/lib/python3.9/site-packages/aiohttp/client.py", line 754, in _ws_connect
    resp = await self.request(
  File ".venv/lib/python3.9/site-packages/aiohttp/client.py", line 542, in _request
    resp = await req.send(conn)
  File ".venv/lib/python3.9/site-packages/aiohttp/client_reqrep.py", line 674, in send
    self.response = response_class(
Process finished with exit code 0
Read more comments on GitHub >

github_iconTop Results From Across the Web

How to ignore deprecation warnings in Python - Stack Overflow
On the more serious note, you can pass the argument -Wi::DeprecationWarning on the command line to the interpreter to ignore the deprecation warnings....
Read more >
python - Shapely deprecation warning message when plotting ...
Now I am having a new pc when I try to plot my geodataframe using : gdf.plot() there is no plot displayed and...
Read more >
Changelog — Python 3.7.15 documentation
gh-97616: Fix multiplying a list by an integer ( list *= int ): detect the integer overflow when the new allocated length is...
Read more >
Release notes for Python 3.5.4
bpo-29742: get_extra_info() raises exception if get called on closed ssl ... bpo-29349: Fix Python 2 syntax in code for building the documentation.
Read more >
deprecationwarning: pkcs | The AI Search Engine You Control
BUILDROOT/python-pyOpenSSL-21.0.0-2.fc35.x86_64/usr/lib/python3.8/site-packages/OpenSSL/SSL.py:1700: in _raise_ssl_error _raise_current_error() _ _ _ _ _ _ ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found