Skip to content
Snippets Groups Projects
Commit f81adac3 authored by Piotr Maślanka's avatar Piotr Maślanka
Browse files

beefed up BogusTerminableThread docs

parent 3f992ea9
No related branches found
No related tags found
No related merge requests found
...@@ -2,3 +2,4 @@ ...@@ -2,3 +2,4 @@
* more time-related calls will accept time strings * more time-related calls will accept time strings
* added optional `delay` argument to `call_in_separate_thread` * added optional `delay` argument to `call_in_separate_thread`
* beefed up BogusTerminableThread docs
...@@ -153,6 +153,10 @@ class SingleStartThread(threading.Thread): ...@@ -153,6 +153,10 @@ class SingleStartThread(threading.Thread):
class BogusTerminableThread: class BogusTerminableThread:
""" """
A mock object that implements threading interface but does nothing A mock object that implements threading interface but does nothing
:ivar running: bool, if it's running
:ivar terminated: bool, if terminated
:ivar daemon: bool, if daemon
""" """
__slots__ = ('running', 'terminated', 'daemon') __slots__ = ('running', 'terminated', 'daemon')
...@@ -161,11 +165,15 @@ class BogusTerminableThread: ...@@ -161,11 +165,15 @@ class BogusTerminableThread:
self.terminated = False self.terminated = False
self.daemon = True self.daemon = True
def is_alive(self): def is_alive(self) -> bool:
"""
:return: if this thread is alive
"""
return not self.terminated and self.running return not self.terminated and self.running
def start(self): def start(self) -> None:
""" """
Set running to True
:raises RuntimeError: thread already terminated or already running :raises RuntimeError: thread already terminated or already running
""" """
if self.terminated: if self.terminated:
...@@ -174,10 +182,19 @@ class BogusTerminableThread: ...@@ -174,10 +182,19 @@ class BogusTerminableThread:
raise RuntimeError('Thread already running') raise RuntimeError('Thread already running')
self.running = True self.running = True
def terminate(self): def terminate(self) -> None:
"""
Set terminated to True.
Note that to set running to False you need to invoke
:meth:`~satella.coding.concurrent.BogusTerminableThread.join` afterwards.
"""
self.terminated = True self.terminated = True
def join(self, timeout=None): def join(self, timeout=None) -> None:
"""
Wait for the pseudo-thread. Sets running to False if thread was terminated.
"""
if self.terminated: if self.terminated:
self.running = False self.running = False
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment