A notification stream with process monitoring

This commit is contained in:
Julien Duponchelle
2015-03-04 16:01:56 +01:00
parent 57f5e7a7d9
commit e9ec5c8a37
15 changed files with 256 additions and 25 deletions

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))