Reset event loop in scheduler if subprocessed & pytest timeout
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index f393be5..f3f8036 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -16,7 +16,7 @@
variables:
PYTEST_ADDOPTS: "--color=yes"
INTEGRATION_CACHE: "${CI_PROJECT_DIR}/cache/integration-cache"
- PYTEST_ARGS: "--color=yes --integration -n 2"
+ PYTEST_ARGS: "--color=yes --timeout=1 --integration -n 2"
TEST_COMMAND: "tox -- ${PYTEST_ARGS}"
EXTERNAL_TESTS_COMMAND: "tox -e py{35,36,37}-external -- ${PYTEST_ARGS}"
COVERAGE_PREFIX: "${CI_JOB_NAME}."
diff --git a/src/buildstream/_scheduler/scheduler.py b/src/buildstream/_scheduler/scheduler.py
index 886867d..6ee20bd 100644
--- a/src/buildstream/_scheduler/scheduler.py
+++ b/src/buildstream/_scheduler/scheduler.py
@@ -235,6 +235,10 @@
failed = any(queue.any_failed_elements() for queue in self.queues)
self.loop = None
+ # Unset the global event loop, if subprocessed
+ if subprocessed:
+ asyncio.set_event_loop_policy(None)
+
# Notify that the loop has been reset
self._notify_front(Notification(NotificationType.RUNNING))
diff --git a/src/buildstream/_stream.py b/src/buildstream/_stream.py
index e62c255..9fdbcd9 100644
--- a/src/buildstream/_stream.py
+++ b/src/buildstream/_stream.py
@@ -172,6 +172,7 @@
# We can now launch another async
self.loop = asyncio.new_event_loop()
+ asyncio.set_event_loop(self.loop)
self._connect_signals()
self._start_listening()
self.loop.set_exception_handler(self._handle_exception)