A notification stream with process monitoring

This commit is contained in:
Julien Duponchelle committed 2015-05-01 13:20:30 +02:00
1 parent 57f5e7a7d9
commit e9ec5c8a37
15 files changed
+256 -25

No files matched your search

+18
View File
@@ -17,6 +17,8 @@
import asyncio
import shutil
import sys
@asyncio.coroutine
@@ -76,3 +78,19 @@ def wait_for_process_termination(process, timeout=10):
yield from asyncio.sleep(0.1)
timeout -= 0.1
raise asyncio.TimeoutError()
@asyncio.coroutine
def _check_process(process, termination_callback):
if not hasattr(sys, "_called_from_test") or not sys._called_from_test:
returncode = yield from process.wait()
if asyncio.iscoroutinefunction(termination_callback):
yield from termination_callback(returncode)
else:
termination_callback(returncode)
def monitor_process(process, termination_callback):
"""Call termination_callback when process die"""
asyncio.async(_check_process(process, termination_callback))