Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Z
Zope
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
Zope
Commits
d7521118
Commit
d7521118
authored
Jan 11, 1999
by
Amos Latteier
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
changed callback mechanism to make it more flexible, also added callback
on close().
parent
e4ec8395
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
30 additions
and
6 deletions
+30
-6
ZServer/PubCore/ZOutPipe.py
ZServer/PubCore/ZOutPipe.py
+15
-3
lib/python/ZServer/PubCore/ZOutPipe.py
lib/python/ZServer/PubCore/ZOutPipe.py
+15
-3
No files found.
ZServer/PubCore/ZOutPipe.py
View file @
d7521118
...
...
@@ -7,8 +7,12 @@ from string import join
TupleType
=
type
(())
class
OutputPipe
:
"""A pipe which can be written to and read from different threads.
Also supports callbacks to notify readers when the pipe has been
written to or has been closed."""
def
__init__
(
self
,
callback
=
None
):
"callback should be a tuple (function,(args,))"
lock
=
thread
.
allocate_lock
()
self
.
_r
=
lock
.
release
self
.
_a
=
lock
.
acquire
...
...
@@ -20,7 +24,15 @@ class OutputPipe:
try
:
self
.
_buf
.
append
(
text
)
finally
:
self
.
_r
()
Wakeup
(
self
.
_callback
)
self
.
notify
()
def
notify
(
self
):
if
self
.
_callback
:
fun
=
self
.
_callback
[
0
]
args
=
self
.
_callback
[
1
]
+
(
self
,)
Wakeup
(
lambda
f
=
fun
,
a
=
args
:
apply
(
f
,
a
))
else
:
Wakeup
()
def
close
(
self
):
self
.
_a
()
...
...
@@ -29,14 +41,14 @@ class OutputPipe:
if
b
:
self
.
_buf
=
tuple
(
b
)
else
:
self
.
_buf
=
None
finally
:
self
.
_r
()
self
.
notify
()
def
read
(
self
):
"""Read data from the pipe
Return None if the pipe is open but has no data.
Return an empty string if the pipe is closed.
"""
print
"read from pipe"
self
.
_a
()
try
:
b
=
self
.
_buf
...
...
lib/python/ZServer/PubCore/ZOutPipe.py
View file @
d7521118
...
...
@@ -7,8 +7,12 @@ from string import join
TupleType
=
type
(())
class
OutputPipe
:
"""A pipe which can be written to and read from different threads.
Also supports callbacks to notify readers when the pipe has been
written to or has been closed."""
def
__init__
(
self
,
callback
=
None
):
"callback should be a tuple (function,(args,))"
lock
=
thread
.
allocate_lock
()
self
.
_r
=
lock
.
release
self
.
_a
=
lock
.
acquire
...
...
@@ -20,7 +24,15 @@ class OutputPipe:
try
:
self
.
_buf
.
append
(
text
)
finally
:
self
.
_r
()
Wakeup
(
self
.
_callback
)
self
.
notify
()
def
notify
(
self
):
if
self
.
_callback
:
fun
=
self
.
_callback
[
0
]
args
=
self
.
_callback
[
1
]
+
(
self
,)
Wakeup
(
lambda
f
=
fun
,
a
=
args
:
apply
(
f
,
a
))
else
:
Wakeup
()
def
close
(
self
):
self
.
_a
()
...
...
@@ -29,14 +41,14 @@ class OutputPipe:
if
b
:
self
.
_buf
=
tuple
(
b
)
else
:
self
.
_buf
=
None
finally
:
self
.
_r
()
self
.
notify
()
def
read
(
self
):
"""Read data from the pipe
Return None if the pipe is open but has no data.
Return an empty string if the pipe is closed.
"""
print
"read from pipe"
self
.
_a
()
try
:
b
=
self
.
_buf
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment