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
7dfa9524
Commit
7dfa9524
authored
4 years ago
by
Piotr Maślanka
Browse files
Options
Downloads
Patches
Plain Diff
added functionality to `ThreadCollection`
parent
81f2a5e9
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
CHANGELOG.md
+1
-1
1 addition, 1 deletion
CHANGELOG.md
satella/__init__.py
+1
-1
1 addition, 1 deletion
satella/__init__.py
satella/coding/concurrent/thread_collection.py
+35
-0
35 additions, 0 deletions
satella/coding/concurrent/thread_collection.py
with
37 additions
and
2 deletions
CHANGELOG.md
+
1
−
1
View file @
7dfa9524
...
@@ -3,4 +3,4 @@
...
@@ -3,4 +3,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
*
beefed up BogusTerminableThread docs
*
added
`ThreadCollection
.add
`
*
added
functionality to
`ThreadCollection`
This diff is collapsed.
Click to expand it.
satella/__init__.py
+
1
−
1
View file @
7dfa9524
__version__
=
'
2.14.47a
3
'
__version__
=
'
2.14.47a
4
'
This diff is collapsed.
Click to expand it.
satella/coding/concurrent/thread_collection.py
+
35
−
0
View file @
7dfa9524
import
threading
import
typing
as
tp
import
typing
as
tp
from
threading
import
Thread
from
threading
import
Thread
...
@@ -15,10 +16,36 @@ class ThreadCollection:
...
@@ -15,10 +16,36 @@ class ThreadCollection:
>>>
tc
.
start
()
>>>
tc
.
start
()
>>>
tc
.
terminate
()
>>>
tc
.
terminate
()
>>>
tc
.
join
()
>>>
tc
.
join
()
This also implements iteration (it will return all the threads in the collection) and
length check.
"""
"""
__slots__
=
(
'
threads
'
,
)
__slots__
=
(
'
threads
'
,
)
def
__len__
(
self
):
return
len
(
self
.
threads
)
def
__iter__
(
self
):
return
iter
(
self
.
threads
)
@classmethod
def
get_currently_running
(
cls
,
include_main_thread
:
bool
=
True
)
->
'
ThreadCollection
'
:
"""
Get all currently running threads as thread collection
:param include_main_thread: whether to include the main thread
:return: a thread collection representing all currently running threads
"""
result
=
[]
for
thread
in
threading
.
enumerate
():
# noinspection PyProtectedMember
if
not
include_main_thread
and
isinstance
(
thread
,
threading
.
_MainThread
):
continue
result
.
append
(
thread
)
return
ThreadCollection
(
result
)
@classmethod
@classmethod
def
from_class
(
cls
,
cls_to_use
,
iteratable
,
**
kwargs
)
->
'
ThreadCollection
'
:
def
from_class
(
cls
,
cls_to_use
,
iteratable
,
**
kwargs
)
->
'
ThreadCollection
'
:
"""
"""
...
@@ -46,6 +73,14 @@ class ThreadCollection:
...
@@ -46,6 +73,14 @@ class ThreadCollection:
def
__init__
(
self
,
threads
:
tp
.
Sequence
[
Thread
]):
def
__init__
(
self
,
threads
:
tp
.
Sequence
[
Thread
]):
self
.
threads
=
list
(
threads
)
self
.
threads
=
list
(
threads
)
def
append
(
self
,
thread
:
Thread
)
->
None
:
"""
Alias for :meth:`~satella.coding.concurrent.ThreadCollection.add`
:param thread: thread to add
"""
self
.
add
(
thread
)
def
add
(
self
,
thread
:
Thread
)
->
None
:
def
add
(
self
,
thread
:
Thread
)
->
None
:
"""
"""
Add a thread to the collection
Add a thread to the collection
...
...
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