-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #17 from Zinkelburger/stop_task_refactor
Refactor task.py abstract `stop`
- Loading branch information
Showing
10 changed files
with
161 additions
and
151 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
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,24 +1,26 @@ | ||
from threading import Thread | ||
from logger import logger | ||
from common import Result | ||
from typing import Callable, Any, Optional | ||
|
||
|
||
class ReturnValueThread(Thread): | ||
def __init__(self, *args, **kwargs): | ||
self._target = None | ||
def __init__(self, *args: Any, **kwargs: Any): | ||
self._target: Callable[..., Result] = None | ||
self._args = args | ||
self._kwargs = kwargs | ||
super().__init__(*args, **kwargs) | ||
self.result = None | ||
self.result: Optional[Result] = None | ||
|
||
def run(self): | ||
def run(self) -> None: | ||
if self._target is None: | ||
logger.error("Called ReturnValueThread with target=None") | ||
return | ||
try: | ||
self.result = self._target(*self._args, **self._kwargs) | ||
except Exception as e: | ||
logger.error(e) | ||
pass | ||
logger.error(f"Thread with target {self._target} experienced exception {e}") | ||
|
||
def join(self, *args, **kwargs): | ||
def join(self, *args: Any, **kwargs: Any) -> Result: | ||
super().join(*args, **kwargs) | ||
return self.result |
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
Oops, something went wrong.