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
f0060c6d
Commit
f0060c6d
authored
10 years ago
by
Piotr Maślanka
Browse files
Options
Downloads
Patches
Plain Diff
Added bidirectional queues (pipes)
parent
4fc908ba
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
threads/__init__.py
+1
-0
1 addition, 0 deletions
threads/__init__.py
threads/pipe.py
+33
-0
33 additions, 0 deletions
threads/pipe.py
threads/unittests/__init__.py
+2
-1
2 additions, 1 deletion
threads/unittests/__init__.py
threads/unittests/pipe.py
+15
-0
15 additions, 0 deletions
threads/unittests/pipe.py
with
51 additions
and
1 deletion
threads/__init__.py
+
1
−
0
View file @
f0060c6d
from
threading
import
Thread
,
Lock
,
RLock
from
threading
import
Thread
,
Lock
,
RLock
from
satella.threads.pipe
import
Pipe
,
create_pipes
class
BaseThread
(
Thread
):
class
BaseThread
(
Thread
):
"""
Thread with internal termination flag
"""
"""
Thread with internal termination flag
"""
...
...
This diff is collapsed.
Click to expand it.
threads/pipe.py
0 → 100644
+
33
−
0
View file @
f0060c6d
import
Queue
class
Pipe
(
Queue
.
Queue
):
"""
Represents a bidirectional inter-thread queue.
Essentially it is a Queue.Queue, so that .put elements
appear in the other queue.
This will contain cyclic references, so it should be
kinda persistent.
Call .close() to terminate that cyclic reference.
"""
Empty
=
Queue
.
Empty
def
__init__
(
self
):
Queue
.
Queue
.
__init__
(
self
)
self
.
other_queue
=
None
def
put
(
self
,
item
,
block
=
True
,
timeout
=
None
):
Queue
.
Queue
.
put
(
self
.
other_queue
,
item
,
block
,
timeout
)
def
create_pipes
():
"""
Returns a pair (tuple) of Pipes connecting to each
other
"""
a
=
Pipe
()
b
=
Pipe
()
a
.
other_queue
=
b
b
.
other_queue
=
a
return
a
,
b
\ No newline at end of file
This diff is collapsed.
Click to expand it.
threads/unittests/__init__.py
+
2
−
1
View file @
f0060c6d
from
monitor
import
MonitorTest
from
monitor
import
MonitorTest
from
basethread
import
ThreadingTest
from
basethread
import
ThreadingTest
\ No newline at end of file
from
pipe
import
PipeTest
\ No newline at end of file
This diff is collapsed.
Click to expand it.
threads/unittests/pipe.py
0 → 100644
+
15
−
0
View file @
f0060c6d
from
satella.threads
import
create_pipes
from
time
import
sleep
import
unittest
class
PipeTest
(
unittest
.
TestCase
):
def
test_pipe
(
self
):
"""
Tests basic pipe predicaments
"""
a
,
b
=
create_pipes
()
a
.
put
(
'
Lol
'
)
self
.
assertEqual
(
b
.
get
(),
'
Lol
'
)
\ No newline at end of file
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