This repository has been archived on 2023-02-07. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
flamenco-worker/flamenco_worker/patch_asyncio.py
Sybren A. Stüvel 05408dc8c1 Cleanup: reformat with Black
Reformat the entire project with Black.

No functional changes.
2021-07-09 14:26:13 +02:00

37 lines
1.0 KiB
Python

"""
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'
"""
def patch_asyncio():
import logging
import sys
log = logging.getLogger(__name__)
if sys.platform == "win32":
log.debug(
"Patching ue._UnixReadPipeTransport.resume_reading not needed on Windows"
)
return
log.debug("Patching ue._UnixReadPipeTransport.resume_reading")
import asyncio.unix_events as ue
orig_resume_reading = ue._UnixReadPipeTransport.resume_reading
def resume_reading(self, *args, **kwargs):
if not self._loop:
return
return orig_resume_reading(self, *args, **kwargs)
ue._UnixReadPipeTransport.resume_reading = resume_reading