forked from autogenhub/autogen
-
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.
Add support for task cancellation (autogenhub#7)
* Add support for task cancellation * add tests to CI * matrix for python testing
- Loading branch information
1 parent
f80c42e
commit 5afbadb
Showing
13 changed files
with
267 additions
and
66 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"python.testing.pytestArgs": [ | ||
"tests" | ||
], | ||
"python.testing.unittestEnabled": false, | ||
"python.testing.pytestEnabled": true | ||
} |
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
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 threading | ||
from asyncio import Future | ||
from typing import Any, Callable, List | ||
|
||
|
||
class CancellationToken: | ||
def __init__(self) -> None: | ||
self._cancelled: bool = False | ||
self._lock: threading.Lock = threading.Lock() | ||
self._callbacks: List[Callable[[], None]] = [] | ||
|
||
def cancel(self) -> None: | ||
with self._lock: | ||
if not self._cancelled: | ||
self._cancelled = True | ||
for callback in self._callbacks: | ||
callback() | ||
|
||
def is_cancelled(self) -> bool: | ||
with self._lock: | ||
return self._cancelled | ||
|
||
def add_callback(self, callback: Callable[[], None]) -> None: | ||
with self._lock: | ||
if self._cancelled: | ||
callback() | ||
else: | ||
self._callbacks.append(callback) | ||
|
||
def link_future(self, future: Future[Any]) -> None: | ||
with self._lock: | ||
if self._cancelled: | ||
future.cancel() | ||
else: | ||
|
||
def _cancel() -> None: | ||
future.cancel() | ||
|
||
self._callbacks.append(_cancel) |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.