Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
satella
Manage
Activity
Members
Labels
Plan
Issues
1
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
public
satella
Commits
f81adac3
You need to sign in or sign up before continuing.
Commit
f81adac3
authored
4 years ago
by
Piotr Maślanka
Browse files
Options
Downloads
Patches
Plain Diff
beefed up BogusTerminableThread docs
parent
3f992ea9
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
CHANGELOG.md
+1
-0
1 addition, 0 deletions
CHANGELOG.md
satella/coding/concurrent/thread.py
+21
-4
21 additions, 4 deletions
satella/coding/concurrent/thread.py
with
22 additions
and
4 deletions
CHANGELOG.md
+
1
−
0
View file @
f81adac3
...
@@ -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
This diff is collapsed.
Click to expand it.
satella/coding/concurrent/thread.py
+
21
−
4
View file @
f81adac3
...
@@ -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
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment