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

Worker: construct ProactorEventLoop on Windows

On Windows, the default event loop is SelectorEventLoop which does
not support subprocesses. ProactorEventLoop should be used instead.

Source: https://docs.python.org/3.5/library/asyncio-subprocess.html
parent 8d2a7d24
Branches
Tags 0.0.5
No related merge requests found
......@@ -54,7 +54,7 @@ def main():
confparser = config.load_config(args.config, args.verbose)
# Construct the AsyncIO loop
loop = asyncio.get_event_loop()
loop = construct_asyncio_loop()
if args.verbose:
log.debug('Enabling AsyncIO debugging')
loop.set_debug(True)
......@@ -111,5 +111,20 @@ def main():
log.warning('Shutting down')
def construct_asyncio_loop() -> asyncio.AbstractEventLoop:
# On Windows, the default event loop is SelectorEventLoop which does
# not support subprocesses. ProactorEventLoop should be used instead.
# Source: https://docs.python.org/3.5/library/asyncio-subprocess.html
import sys
if sys.platform == 'win32':
loop = asyncio.ProactorEventLoop()
asyncio.set_event_loop(loop)
else:
loop = asyncio.get_event_loop()
return loop
if __name__ == '__main__':
main()
......@@ -13,9 +13,10 @@ class TaskUpdateQueueTest(AbstractWorkerTest):
def setUp(self):
from flamenco_worker.upstream import FlamencoManager
from flamenco_worker.upstream_update_queue import TaskUpdateQueue
from flamenco_worker.cli import construct_asyncio_loop
from mock_responses import CoroMock
self.asyncio_loop = asyncio.get_event_loop()
self.asyncio_loop = construct_asyncio_loop()
self.shutdown_future = self.asyncio_loop.create_future()
self.manager = Mock(spec=FlamencoManager)
......
......@@ -8,12 +8,13 @@ import requests
class AbstractWorkerTest(unittest.TestCase):
def setUp(self):
from flamenco_worker.cli import construct_asyncio_loop
from flamenco_worker.upstream import FlamencoManager
from flamenco_worker.worker import FlamencoWorker
from flamenco_worker.runner import TaskRunner
from flamenco_worker.upstream_update_queue import TaskUpdateQueue
self.asyncio_loop = asyncio.get_event_loop()
self.asyncio_loop = construct_asyncio_loop()
self.shutdown_future = self.asyncio_loop.create_future()
self.manager = Mock(spec=FlamencoManager)
......@@ -116,7 +117,9 @@ class WorkerStartupTest(AbstractWorkerTest):
class TestWorkerTaskFetch(AbstractWorkerTest):
def setUp(self):
super().setUp()
self.loop = asyncio.get_event_loop()
from flamenco_worker.cli import construct_asyncio_loop
self.loop = construct_asyncio_loop()
self.worker.loop = self.loop
def run_loop_for(self, seconds: float):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment