-
-
Notifications
You must be signed in to change notification settings - Fork 369
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Kernel subshells (JEP91) implementation (#1249)
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
- Loading branch information
1 parent
0fa5439
commit 3089438
Showing
16 changed files
with
988 additions
and
68 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 |
---|---|---|
@@ -1,40 +1,11 @@ | ||
"""A thread for a control channel.""" | ||
from threading import Event, Thread | ||
|
||
from anyio import create_task_group, run, to_thread | ||
from .thread import CONTROL_THREAD_NAME, BaseThread | ||
|
||
CONTROL_THREAD_NAME = "Control" | ||
|
||
|
||
class ControlThread(Thread): | ||
class ControlThread(BaseThread): | ||
"""A thread for a control channel.""" | ||
|
||
def __init__(self, **kwargs): | ||
"""Initialize the thread.""" | ||
Thread.__init__(self, name=CONTROL_THREAD_NAME, **kwargs) | ||
self.pydev_do_not_trace = True | ||
self.is_pydev_daemon_thread = True | ||
self.__stop = Event() | ||
self._task = None | ||
|
||
def set_task(self, task): | ||
self._task = task | ||
|
||
def run(self): | ||
"""Run the thread.""" | ||
self.name = CONTROL_THREAD_NAME | ||
run(self._main) | ||
|
||
async def _main(self): | ||
async with create_task_group() as tg: | ||
if self._task is not None: | ||
tg.start_soon(self._task) | ||
await to_thread.run_sync(self.__stop.wait) | ||
tg.cancel_scope.cancel() | ||
|
||
def stop(self): | ||
"""Stop the thread. | ||
This method is threadsafe. | ||
""" | ||
self.__stop.set() | ||
super().__init__(name=CONTROL_THREAD_NAME, **kwargs) |
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.