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: ProactorEventLoop locks up on close call
Type: behavior Stage: resolved
Components: asyncio Versions: Python 3.7, Python 3.6
process
Status: closed Resolution: duplicate
Dependencies: Superseder: [Windows] asyncio: support signal handlers on Windows (feature request)
View: 23057
Assigned To: Nosy List: asvetlov, rt121212121, vstinner, yselivanov
Priority: normal Keywords:

Created on 2018-01-25 03:24 by rt121212121, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
bug.py rt121212121, 2018-01-25 03:24
Messages (2)
msg310655 - (view) Author: Roger Taylor (rt121212121) Date: 2018-01-25 03:24
The following problem only occurs when I use ProactorEventLoop.  If I use 'asyncio.get_event_loop()' it exits normally, rather than infinite looping in IOCP land.

1. I run the attached 'bug.py' script in a DOS window.  It is a slightly modified version of the asyncio echo server example.
2. It reaches 'loop.run_forever()' and blocks.  I can make connections here and use it as an echo server.  Or make no connections.
3. I press Ctrl-C in the DOS window.  Nothing happens.
4. I do a raw connection with Putty and try some input.
5. 'run_forever()' exits and the script proceeds to the 'loop.close()' call.  Before this is invoked and the infinite loop entered, I see the script output '<ProactorEventLoop running=False closed=False debug=False>'.

At this point, the script locks up and never reaches the next line.  It can be interrupted with another Ctrl-C, and the following stack track is seen:

	Traceback (most recent call last):
	  File "bug.py", line 39, in <module>
		loop.close()
	  File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\asyncio\proactor_events.py", line 437, in close
		self._proactor.close()
	  File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\asyncio\windows_events.py", line 745, in close
		if not self._poll(1):
	  File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\asyncio\windows_events.py", line 673, in _poll
		status = _overlapped.GetQueuedCompletionStatus(self._iocp, ms)
	KeyboardInterrupt

The following code in 'windows_events.py:IocpProactor.close' is looping infinitely.

        while self._cache:
            if not self._poll(1):
                logger.debug('taking long time to close proactor')

Note that '_poll' does not actually return anything.
msg333693 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2019-01-15 12:24
bug.py calls loop.run_forever() but nothing calls stops the loop. If you add loop.stop() to handle_incoming_connection(), the script exits properly as soon as a client connects and sends some data.

> 3. I press Ctrl-C in the DOS window.  Nothing happens.

This issue has been fixed by bpo-23057. So I qualify this issue as a duplicate of bpo-23057.
History
Date User Action Args
2022-04-11 14:58:57adminsetgithub: 76842
2019-01-15 12:24:11vstinnersetstatus: open -> closed

superseder: [Windows] asyncio: support signal handlers on Windows (feature request)

nosy: + vstinner
messages: + msg333693
resolution: duplicate
stage: resolved
2018-01-29 11:59:20pitrousetversions: + Python 3.7
2018-01-25 03:24:15rt121212121create