Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b1e4573

Browse files
authored
bpo-34323: Enhance IocpProactor.close() log (GH-11555)
IocpProactor.close() now uses time to decide when to log: wait 1 second before the first log, then log every second. Log also the number of seconds since close() was called.
1 parent 06f8b57 commit b1e4573

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

Lib/asyncio/windows_events.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import msvcrt
88
import socket
99
import struct
10+
import time
1011
import weakref
1112

1213
from . import events
@@ -802,10 +803,21 @@ def close(self):
802803
context['source_traceback'] = fut._source_traceback
803804
self._loop.call_exception_handler(context)
804805

805-
# wait until all cancelled overlapped future complete
806+
# Wait until all cancelled overlapped complete: don't exit with running
807+
# overlapped to prevent a crash. Display progress every second if the
808+
# loop is still running.
809+
msg_update = 1.0
810+
start_time = time.monotonic()
811+
next_msg = start_time + msg_update
806812
while self._cache:
807-
if not self._poll(1):
808-
logger.debug('taking long time to close proactor')
813+
if next_msg <= time.monotonic():
814+
logger.debug('IocpProactor.close(): '
815+
'loop is running after closing for %.1f seconds',
816+
time.monotonic() - start_time)
817+
next_msg = time.monotonic() + msg_update
818+
819+
# handle a few events, or timeout
820+
self._poll(msg_update)
809821

810822
self._results = []
811823

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
:mod:`asyncio`: Enhance ``IocpProactor.close()`` log: wait 1 second before
2+
the first log, then log every second. Log also the number of seconds since
3+
``close()`` was called.

0 commit comments

Comments
 (0)