forked from gorakhargosh/watchdog
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve typing references for events
Closes gorakhargosh#1040.
- Loading branch information
Showing
6 changed files
with
50 additions
and
43 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
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 |
---|---|---|
@@ -1,27 +1,30 @@ | ||
from __future__ import annotations | ||
|
||
import logging | ||
from typing import TYPE_CHECKING | ||
|
||
from watchdog.utils import BaseThread | ||
|
||
if TYPE_CHECKING: | ||
import subprocess | ||
from typing import Callable | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
class ProcessWatcher(BaseThread): | ||
def __init__(self, popen_obj, process_termination_callback): | ||
def __init__(self, popen_obj: subprocess.Popen, process_termination_callback: Callable | None) -> None: | ||
super().__init__() | ||
self.popen_obj = popen_obj | ||
self.process_termination_callback = process_termination_callback | ||
|
||
def run(self): | ||
while True: | ||
if self.popen_obj.poll() is not None: | ||
break | ||
def run(self) -> None: | ||
while self.popen_obj.poll() is None: | ||
if self.stopped_event.wait(timeout=0.1): | ||
return | ||
|
||
try: | ||
if not self.stopped_event.is_set(): | ||
if not self.stopped_event.is_set() and self.process_termination_callback: | ||
self.process_termination_callback() | ||
except Exception: | ||
logger.exception("Error calling process termination callback") |