-
Notifications
You must be signed in to change notification settings - Fork 128
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
RuntimeError: Event loop is closed in multiprocessing enviroments (celery). #46
Comments
I don't quite understand the issue. Is that the event loop used by |
Yes, other code packages often interfere with the event loop by closing it, it is not a problem of the vt-py itself. However, it seems to me that it could defend itself against closing the event loop by maintaining its own, e.g. in a dedicated thread for that. |
I'm not sure about that. When you are using |
Sure, you're right, of course. I am not reporting the error in vt-py. It's a suggestion based on my experience. Unfortunately many libraries implement such protective measures, because in environments like celery you have no chance as a user to control when the event loop for a given process (worker process) is closed. As far as I remember I wrote a suggestion that vt-py may give "manage your own event loop" option, because it was something I had to do myself anyway. So apart from saying "hey why not consider this", the issue is destined to be closed :) |
I'm ok with adding protective measures if that helps, but I don't know what type of protective measures we can add. Do you have some specific measure in mind? |
By the end of the week I'll dig out my patches, make them civilized, and do a pull request. I don't remember the details at the moment, the topic is a bit old but since my workplace didn't explode I guess it works ok ;) |
Ok, now I remember. The whole point is that when the event loop is only closed but exists then get_event_loop does not throw a runtime exception. In an environment like celery, where you have several processes and you don't control which one your code runs in, and on top of that the code of other libraries closes the event loop (because that's the python idiom - treat the loop as your own resource) you're not able to meaningfully guarantee as a user that the loop will be in a good state. Run the following test with vt-py master and then with my fork:
|
Hi,
First of all sorry for not providing PR, lack of spare time.
The problem I faced is not strictly an vt-py issue but i beleave that protection against such a problem can also be added here.
In short words, i ve got software where celery tasks using vt-py are processesd among other tasks, other tasks are using packages containg async code too. While trying to debug error mentioned in title I came up with PoC of problem/possible solution. I believe that code will be best description.
Right now the only more or less clear solution is wrapping async code using threads.
BR
Artur Augustyniak
The text was updated successfully, but these errors were encountered: