Skip to content
Snippets Groups Projects
Commit ad505ee8 authored by Sybren A. Stüvel's avatar Sybren A. Stüvel
Browse files

Worker: patching asyncio to avoid an occasional crash

Thanks to David Keeney for helping out with this.
parent f4092726
No related branches found
No related tags found
No related merge requests found
...@@ -24,6 +24,10 @@ def main(): ...@@ -24,6 +24,10 @@ def main():
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
log.debug('Starting') log.debug('Starting')
# Patch AsyncIO
from . import patch_asyncio
patch_asyncio.patch_asyncio()
# Construct the AsyncIO loop # Construct the AsyncIO loop
loop = construct_asyncio_loop() loop = construct_asyncio_loop()
if args.verbose: if args.verbose:
......
"""
Patches a safer version of resume_reading into the asyncio.unix_events._UnixReadPipeTransport class.
This prevents an error at the end of a subprocess execution:
File "/usr/lib/python3.x/asyncio/unix_events.py", line 364, in resume_reading
self._loop.add_reader(self._fileno, self._read_ready)
AttributeError: 'NoneType' object has no attribute 'add_reader'
"""
import asyncio.unix_events as ue
def patch_asyncio():
import logging
log = logging.getLogger(__name__)
log.debug('Patching ue._UnixReadPipeTransport.resume_reading')
orig_resume_reading = ue._UnixReadPipeTransport.resume_reading
def resume_reading(self, *args, **kwargs):
if not self._loop:
return
return orig_resume_reading(*args, **kwargs)
ue._UnixReadPipeTransport.resume_reading = resume_reading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment