-
-
Notifications
You must be signed in to change notification settings - Fork 704
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[watchmedo] Make auto-restart restart the sub-process if it terminates (
- Loading branch information
Showing
4 changed files
with
55 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import logging | ||
import time | ||
|
||
from watchdog.utils import BaseThread | ||
|
||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
class ProcessWatcher(BaseThread): | ||
def __init__(self, popen_obj, process_termination_callback): | ||
super().__init__() | ||
self.popen_obj = popen_obj | ||
self.process_termination_callback = process_termination_callback | ||
|
||
def run(self): | ||
while True: | ||
if self.stopped_event.is_set(): | ||
return | ||
if self.popen_obj.poll() is not None: | ||
break | ||
time.sleep(0.1) | ||
|
||
try: | ||
self.process_termination_callback() | ||
except Exception: | ||
logger.exception("Error calling process termination callback") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters