Closed WildsG closed 2 years ago
Hello WildsG!
I dont know celery, i only have read the abstract desctiption. From my understanding, it is made to organize multiple request based routines but websockets are not request based, its a persistent data stream. To work request based you should switch to REST api instead.
If you have 3 request based tasks you can schedule them with celery that seems to be similar to asyncio or actually is using asyncio in the background. create_stream()
does not need such a handling, because its a not blocking function and running paralell in a separate thread.
What you can try is the nested_async implementation that is suggested in the posts of your investigation. But i am not sure if thats really the "right" way.
Best regards, Oliver
Feel free to reopen if needed....
Check this or we will delete your issue. (fill in the checkbox with an X like so: [x])
Select one:
Environment
What kind of internet connection do you have?
Wifi, Download/Upload 100Mbps
Average system load (CPU)
30% 6 cores
Hardware specification
16 GB Ram, 256GB ssd, AMD Ryzen 5 4500U 3948Mhz, Amd Radeon(TM) Graphics 512MB
Operating System? (include version)
Options
Which endpoint do you connect?
Endpoint - binance.com
Python Version Requirement
Exact Python Version?
3.9.5
Pip Version?
21.0.1
Dependencies
UNICORN Binance WebSocket API Version?
1.30.0
Description of your issue
I've written a script for scrapping data from binance via websockets, it works standalone - when I simply run the python script from command line. Unfortunately, this is not enough for me and I want to manage my scripts via "celery" task manager in python (package is listed above).
When I'm trying to run my code via a celery task, it fails on BinanceWebSocketApiManager._create_stream_thread() and shows me this error:
It appears to be that somehow multithreading in your package and in celery conflict with each other in some way, because as I mentioned earlier, my code works well when I just run it from command line.
To reproduce this error, you should simply setup celery on your machine and try to run a task, which has a " binance_websocket_api_manager.create_stream" call.
This should trigger the error, as I can't really run any tasks that would execute stream connection from your library.
Some Notes: I've been reading about similar issue others were having and it appears that the culprit is from asyncio package your code uses. Here's the post: https://stackoverflow.com/questions/46827007/runtimeerror-this-event-loop-is-already-running-in-python