This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Interpreter hang on self._epoll.poll(timeout, max_ev)
Type: behavior Stage: resolved
Components: asyncio Versions: Python 3.5
process
Status: closed Resolution: works for me
Dependencies: Superseder:
Assigned To: Nosy List: NCode, asvetlov, k1.hedayati, yselivanov
Priority: normal Keywords:

Created on 2017-03-10 09:47 by k1.hedayati, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
loop_stop_problem.zip NCode, 2018-01-31 17:13
Messages (3)
msg289344 - (view) Author: Keyvan Hedayati (k1.hedayati) Date: 2017-03-10 09:47
Hello
We have an issue with our application, it randomly hangs and doesn't respond to new requests, at first we thought the problem lies within our code but after attaching to hanged process using gdb I couldn't find any code related to our application so I thought it might be python bug.
Here is the info extracted from gdb:
https://gist.github.com/k1-hedayati/96e28bf590c4392840650902cb5eceda
Python 3.5.2

We run multiple instances of our application and they are fine for a couple of days/hours but suddenly one of them starts hanging and others follow and unfortunately we can't reproduce the problem.
I'll be glad to receive any advice on how to solve or debug this issue.
msg308964 - (view) Author: Andrew Svetlov (asvetlov) * (Python committer) Date: 2017-12-23 19:52
I see no hang in attached snapshot but notmal behavior.

asyncio iterates over epoll.poll constantly waiting for network events or timeout.

Closing the issue.
msg311345 - (view) Author: Niko Fink (NCode) Date: 2018-01-31 17:13
I recently had a similar issue, a MWE can be found here (and also attached):
https://gist.github.com/N-Coder/89b1be8e5cfb83b1b03ade8485676982
As soon as `loop.stop` in loop_stop_problem.py:44 is called in a non-threadsafe way from another thread, i.e. without loop.call_soon_threadsafe, the loop seems to hang in `self._epoll.poll(timeout, max_ev)`.
This can be seen when comparing the two outputs in threadunsafe_loop_stop.log (without loop.call_soon_threadsafe) and call_soon_threadsafe_loop_stop.log (with loop.call_soon_threadsafe). Please note the time difference after "Waiting for loop join".
The loop seems to hang until the (seemingly random) epoll timeout occurs, or the next pending events needs to be processed (which might take quite some time).

There is also no explicit note about this behavior in the doc of the function (https://docs.python.org/3/library/asyncio-eventloop.html#asyncio.AbstractEventLoop.stop), only a small note in the doc of AbstractEventLoop, informing you about the non-thread-safety of the whole class.
Also, other methods like `call_at` use `BaseEventLoop._check_thread` (https://github.com/python/cpython/blob/3.6/Lib/asyncio/base_events.py#L549) to check for violations when running in debug mode. Unfortunately, `stop` doesn't make those checks.
All this together makes this bug very hard to find.

So, i'd vote for adding a short `if self._debug: self._check_thread()` to the `stop` method.
History
Date User Action Args
2022-04-11 14:58:44adminsetgithub: 73966
2018-01-31 17:13:43NCodesetfiles: + loop_stop_problem.zip
nosy: + NCode
messages: + msg311345

2017-12-23 19:52:31asvetlovsetstatus: open -> closed

nosy: + asvetlov
messages: + msg308964

resolution: works for me
stage: resolved
2017-03-10 17:26:08gvanrossumsetnosy: - gvanrossum
2017-03-10 09:47:54k1.hedayaticreate