-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' into Acquisition_BrightCentralStar
- Loading branch information
Showing
17 changed files
with
464 additions
and
118 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,3 +12,4 @@ python: | |
install: | ||
- method: pip | ||
path: . | ||
- requirements: docs/requirements.txt |
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 @@ | ||
sphinx-rtd-theme |
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 |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import asyncio | ||
import logging | ||
from typing import Optional, Coroutine, Any, Callable | ||
|
||
from pyobs.utils.exceptions import SevereError | ||
|
||
log = logging.getLogger(__name__) | ||
|
||
|
||
class BackgroundTask: | ||
def __init__(self, func: Callable[..., Coroutine[Any, Any, None]], restart: bool) -> None: | ||
self._func: Callable[..., Coroutine[Any, Any, None]] = func | ||
self._restart: bool = restart | ||
self._task: Optional[asyncio.Future] = None | ||
|
||
def start(self) -> None: | ||
self._task = asyncio.create_task(self._func()) | ||
self._task.add_done_callback(self._callback_function) | ||
|
||
def _callback_function(self, args=None) -> None: | ||
try: | ||
exception = self._task.exception() | ||
except asyncio.CancelledError: | ||
return | ||
|
||
if isinstance(exception, SevereError): | ||
raise exception | ||
elif exception is not None: | ||
log.error("Exception %s in task %s.", exception, self._func.__name__) | ||
|
||
if self._restart: | ||
log.error("Background task for %s has died, restarting...", self._func.__name__) | ||
self.start() | ||
else: | ||
log.error("Background task for %s has died, quitting...", self._func.__name__) | ||
|
||
def stop(self) -> None: | ||
if self._task is not None: | ||
self._task.cancel() |
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
Oops, something went wrong.