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
4418cddf
Commit
4418cddf
authored
Oct 16, 2018
by
Josh Snyder
Committed by
Jason Madden
Oct 16, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Provide a context manager API to prevent memory leaks in gevent.iwait()
parent
adb4e9b4
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
31 additions
and
0 deletions
+31
-0
src/gevent/__hub_primitives.pxd
src/gevent/__hub_primitives.pxd
+4
-0
src/gevent/_hub_primitives.py
src/gevent/_hub_primitives.py
+6
-0
src/greentest/test__iwait.py
src/greentest/test__iwait.py
+21
-0
No files found.
src/gevent/__hub_primitives.pxd
View file @
4418cddf
...
@@ -58,6 +58,10 @@ cdef class _WaitIterator:
...
@@ -58,6 +58,10 @@ cdef class _WaitIterator:
cdef
_begin
(
self
)
cdef
_begin
(
self
)
cdef
_cleanup
(
self
)
cdef
_cleanup
(
self
)
cpdef
__enter__
(
self
)
cpdef
__exit__
(
self
,
typ
,
value
,
tb
)
cpdef
iwait_on_objects
(
objects
,
timeout
=*
,
count
=*
)
cpdef
iwait_on_objects
(
objects
,
timeout
=*
,
count
=*
)
cpdef
wait_on_objects
(
objects
=*
,
timeout
=*
,
count
=*
)
cpdef
wait_on_objects
(
objects
=*
,
timeout
=*
,
count
=*
)
...
...
src/gevent/_hub_primitives.py
View file @
4418cddf
...
@@ -168,6 +168,12 @@ class _WaitIterator(object):
...
@@ -168,6 +168,12 @@ class _WaitIterator(object):
except
:
# pylint:disable=bare-except
except
:
# pylint:disable=bare-except
traceback
.
print_exc
()
traceback
.
print_exc
()
def
__enter__
(
self
):
return
self
def
__exit__
(
self
,
typ
,
value
,
tb
):
self
.
_cleanup
()
def
iwait_on_objects
(
objects
,
timeout
=
None
,
count
=
None
):
def
iwait_on_objects
(
objects
,
timeout
=
None
,
count
=
None
):
"""
"""
...
...
src/greentest/test__iwait.py
View file @
4418cddf
...
@@ -16,5 +16,26 @@ class Testiwait(greentest.TestCase):
...
@@ -16,5 +16,26 @@ class Testiwait(greentest.TestCase):
ready
=
next
(
gevent
.
iwait
((
sem1
,
sem2
)))
ready
=
next
(
gevent
.
iwait
((
sem1
,
sem2
)))
self
.
assertEqual
(
sem1
,
ready
)
self
.
assertEqual
(
sem1
,
ready
)
def
test_iwait_partial
(
self
):
# Test that the iwait context manager allows the iterator to be
# consumed partially without a memory leak.
sem
=
Semaphore
()
let
=
gevent
.
spawn
(
sem
.
release
)
with
gevent
.
iwait
((
sem
,),
timeout
=
0.01
)
as
iterator
:
self
.
assertEqual
(
sem
,
next
(
iterator
))
let
.
get
()
def
test_iwait_nogarbage
(
self
):
sem1
=
Semaphore
()
sem2
=
Semaphore
()
let
=
gevent
.
spawn
(
sem1
.
release
)
with
gevent
.
iwait
((
sem1
,
sem2
))
as
iterator
:
self
.
assertEqual
(
sem1
,
next
(
iterator
))
assert
len
(
sem2
.
_links
)
==
1
assert
sem2
.
_links
is
None
or
len
(
sem2
.
_links
)
==
0
let
.
get
()
if
__name__
==
'__main__'
:
if
__name__
==
'__main__'
:
greentest
.
main
()
greentest
.
main
()
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