ccxt
ccxt copied to clipboard
ccxt async support suddenly throwing error - attached to a different loop
Operating System
MacOS
Programming Languages
Python
CCXT Version
^4.3.37 to latest
Description
Today when I start my application on local mac book, async error thrown that I've never seen before. Please refer the attached trace log.
Code
File "/work/.venv/lib/python3.11/site-packages/ccxt/async_support/binance.py", line 9332, in fetch_positions
return await self.fetch_positions_risk(symbols, params)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/work/.venv/lib/python3.11/site-packages/ccxt/async_support/binance.py", line 9403, in fetch_positions_risk
await self.load_markets()
File "/work/.venv/lib/python3.11/site-packages/ccxt/async_support/base/exchange.py", line 276, in load_markets
raise e
File "/work/.venv/lib/python3.11/site-packages/ccxt/async_support/base/exchange.py", line 272, in load_markets
result = await self.markets_loading
^^^^^^^^^^^^^^^^^^^^^^^^^^
RuntimeError: Task <Task pending name='Task-15' coro=<check_account() running at /work/app/scheduler/account_monitor.py:96> cb=[Task.task_wakeup()]> got Future <Task pending name='Task-44' coro=<Exchange.load_markets_helper() running at /work/.venv/lib/python3.11/site-packages/ccxt/async_support/base/exchange.py:253>> attached to a different loop
I'm also running this application on a cloud VM. It works well now. So I all changed libraries versions to the same with cloud's But still same error. I think it's only happening on macOS. Could it be a problem of latest MacOS?
@ggree1
Could you provide code snippet that we can reproduce this locally?
@ggree1
Could you provide code snippet that we can reproduce this locally?
My code is not that special, just simply using ccxt async support code. But after upgrading my macOS version to 14.5 (sonoma), there is a crash with ccxt async support and fastapi-utils library which I use for scheduling job on async code with @repeat_every decorator.
aiohttp==3.9.5 this will help. 3.10.x version causes this error
aiohttp==3.9.5 this will help. 3.10.x version causes this error
Thanks for the reploy! But it's already using aiohttp 3.9.5. 3.10.x also the same error.
coro=<Exchange.load_markets_helper() running at /..../.venv/lib/python3.11/site-packages/ccxt/async_support/base/exchange.py:253>> attached to a different loop
aiohttp==3.9.5 this will help. 3.10.x version causes this error
Thanks for the reploy! But it's already using aiohttp 3.9.5. 3.10.x also the same error.
coro=<Exchange.load_markets_helper() running at /..../.venv/lib/python3.11/site-packages/ccxt/async_support/base/exchange.py:253>> attached to a different loop
Well. I don't know, I only changed aiohttp>=3.8 to aiohttp==3.9.5 and it worked for me
same issue, 3.9.5 same error. I tried a lot as I am not such familiar with async but failed. The reason is you started another thread and trying to call the await I guess, it doesn't happens in watch_order or something, just the aiohttp lib.
2024-08-28 15:50:21,988 - root - ERROR - Error fetching positions for 2825-7cd23c81b84ddb4be2d1cae8597b3c44.binanceusdm: Task <Task pending name='Task-21' coro=<OrderMessageNotifier.position_update_monitor() running at /Users/hoho/Documents/GitHub/***/services/OrderMessageNotifier.py:445>> got Future <Task pending name='Task-11' coro=<Exchange.load_markets_helper() running at /Users/hoho/Documents/GitHub/***/.venv/lib/python3.11/site-packages/ccxt/async_support/base/exchange.py:261> wait_for=<Future pending cb=[Task.__wakeup()]> cb=[Task.__wakeup(), <1 more>, Task.__wakeup()]> attached to a different loop
I got my problem fixed.
what was the solution @nov30th ?
what was the solution @nov30th ?
如果使用异步方法或者操作,谨慎使用多线程多进程。至少我将多账号的ccxt使用了多个python程序处理,一劳永逸。多个不同的进程或者线程操作一个什么异步loop就会出现这样的问题。