Created on 2019-04-14 05:57 by dantimofte, last changed 2019-04-17 13:07 by asvetlov. This issue is now closed.
after this new tasks are not being processed, trying to stop event loop with stop() is not working.
With asyncio.sleep uncomment it will block after 4 cycles.
Callin `self._write_to_self()` from `loop.stop()` should fix your problem.
Would you provide a patch?
i will provide a patch, i'll make a pull request next week.
a call to self._write_to_self() should also be added to create_task() before it returns . i'll make the correction for this as well.
Usually you create tasks from async code, where the `_write_to_self()` call is not needed.
Handling writing to self-pipe is not free, starting very many tasks at once can hit performance.
Stopping the loop is another beast, we can perform relative slow operations in such calls.
Thinking more about the issue I'm inclining to reject my initial proposal.
If you want to stop a loop from signal handler you should make `loop.call_soon_threadsafe(loop.stop)` call because `loop.stop()` is not thread-safe operation by definition.
Threadsafe call solves your problem, isn't it?
`loop.call_soon_threadsafe(loop.stop)` solves the problem because it has the write_to_self there. I can use that or call loop._write_to_self() myself before calling loop.stop().
In my code i'm stoping the loop from the exception_handler not signal. The code was a small example i thought of that reproduces the described behaviour.
You can close the issue if it's ok for you.
Technically signal handlers are called from main thread, while loop can be executed in another one.
*In general* `call_soon_threadsafe()` is the correct solution.