You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
(following code is attached as well)
import asyncio
import time
workaround=Falseasyncdefslow_proc():
proc=awaitasyncio.create_subprocess_exec('sleep', '10', stdout=asyncio.subprocess.PIPE)
try:
returnawaitproc.stdout.read()
exceptasyncio.CancelledError:
ifworkaround:
proc.terminate()
time.sleep(0.1) # hope the machine is not too busyasyncdeffunc():
try:
returnawaitasyncio.wait_for(slow_proc(), timeout=0.1)
exceptasyncio.TimeoutError:
return'timeout'defmain():
whileTrue:
print('test')
asyncio.run(func())
main()
Run above code, it may work without error message (expected behavior).
However, depends on timing, it may show warning/error messages
case 1.
Loop <_UnixSelectorEventLoop running=False closed=True debug=False> that handles pid 1257652 is closed
case 2.
Exception ignored in: <function BaseSubprocessTransport.__del__ at 0x7fcbcfc66160>
Traceback (most recent call last):
File "/usr/lib/python3.8/asyncio/base_subprocess.py", line 126, in __del__self.close()
File "/usr/lib/python3.8/asyncio/base_subprocess.py", line 104, in close
proto.pipe.close()
File "/usr/lib/python3.8/asyncio/unix_events.py", line 536, in closeself._close(None)
File "/usr/lib/python3.8/asyncio/unix_events.py", line 560, in _closeself._loop.call_soon(self._call_connection_lost, exc)
File "/usr/lib/python3.8/asyncio/base_events.py", line 719, in call_soonself._check_closed()
File "/usr/lib/python3.8/asyncio/base_events.py", line 508, in _check_closedraiseRuntimeError('Event loop is closed')
RuntimeError: Event loop is closed
Although running tasks will be cancelled when asyncio.run is finishing, subprocess' exit handler may be invoked after the event loop is closed.
In above code, I provided a workaround. However it just mitigates the problem and not really fix the root cause.
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: