Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gevent
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
gevent
Commits
772ff231
Commit
772ff231
authored
Jul 30, 2009
by
Denis Bilenko
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
proc: add joinall; fix memleak in waitall; make killall use links
- also use queue.Queue instead of coros.Queue
parent
80fdf951
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
35 additions
and
39 deletions
+35
-39
gevent/proc.py
gevent/proc.py
+35
-39
No files found.
gevent/proc.py
View file @
772ff231
...
@@ -77,6 +77,7 @@ and wait for all them to complete. Such function is provided by this module.
...
@@ -77,6 +77,7 @@ and wait for all them to complete. Such function is provided by this module.
"""
"""
import
sys
import
sys
from
gevent
import
coros
,
greenlet
,
core
from
gevent
import
coros
,
greenlet
,
core
from
gevent.queue
import
Queue
import
traceback
import
traceback
__all__
=
[
'LinkedExited'
,
__all__
=
[
'LinkedExited'
,
...
@@ -171,47 +172,42 @@ class LinkToCallable(Link):
...
@@ -171,47 +172,42 @@ class LinkToCallable(Link):
self
.
listener
(
source
)
self
.
listener
(
source
)
def
waitall
(
lst
,
trap_errors
=
False
,
queue
=
None
):
# QQQ add timeout
def
joinall
(
sources
,
trap_errors
=
True
,
queue
=
None
):
if
queue
is
None
:
if
queue
is
None
:
queue
=
coros
.
Queue
()
queue
=
Queue
()
index
=
-
1
links
=
[]
for
(
index
,
linkable
)
in
enumerate
(
lst
):
try
:
linkable
.
link
(
decorate_send
(
queue
,
index
))
for
source
in
sources
:
len
=
index
+
1
links
.
append
(
source
.
link
(
queue
.
put
))
results
=
[
None
]
*
len
for
_
in
xrange
(
len
(
sources
)):
count
=
0
completed
=
queue
.
get
()
while
count
<
len
:
if
not
trap_errors
and
completed
.
has_exception
():
try
:
greenlet
.
getcurrent
().
throw
(
*
completed
.
exc_info
())
index
,
value
=
queue
.
wait
()
finally
:
except
Exception
:
for
link
in
links
:
if
not
trap_errors
:
link
.
cancel
()
raise
else
:
results
[
index
]
=
value
def
waitall
(
sources
,
trap_errors
=
False
,
queue
=
None
):
count
+=
1
joinall
(
sources
,
trap_errors
=
trap_errors
,
queue
=
queue
)
return
results
return
[
source
.
value
for
source
in
sources
]
class
decorate_send
(
object
):
def
killall
(
sources
,
exception
=
ProcExit
,
block
=
False
,
polling_period
=
0.2
):
waiter
=
Waiter
()
def
__init__
(
self
,
event
,
tag
):
core
.
active_event
(
greenlet
.
_killall
,
sources
,
exception
,
waiter
)
self
.
_event
=
event
if
block
:
self
.
_tag
=
tag
alive
=
waiter
.
wait
()
if
alive
:
def
__repr__
(
self
):
try
:
params
=
(
type
(
self
).
__name__
,
self
.
_tag
,
self
.
_event
)
joinall
(
alive
,
trap_errors
=
True
)
return
'<%s tag=%r event=%r>'
%
params
except
TypeError
:
greenlet
.
_joinall
(
alive
,
polling_period
=
polling_period
)
def
__getattr__
(
self
,
name
):
# QQQ a) use links for all the greenlets we can and poll the others
assert
name
!=
'_event'
# QQQ b) have only one unversal version of killall, waitall, joinall etc
return
getattr
(
self
.
_event
,
name
)
# QQQ the current dichotomy of greenlets and procs is confusing
def
send
(
self
,
value
=
None
):
self
.
_event
.
send
((
self
.
_tag
,
value
))
# XXX this killall should actually be aware of link() and use it to avoid polling
killall
=
greenlet
.
killall
class
NotUsed
(
object
):
class
NotUsed
(
object
):
...
...
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