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
d228edda
Commit
d228edda
authored
Mar 15, 2016
by
Jason Madden
Browse files
Options
Browse Files
Download
Plain Diff
merge master
parents
52a74469
5ef43ad7
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
47 additions
and
19 deletions
+47
-19
gevent/event.py
gevent/event.py
+14
-19
greentest/test__event.py
greentest/test__event.py
+33
-0
No files found.
gevent/event.py
View file @
d228edda
...
...
@@ -12,7 +12,7 @@ __all__ = ['Event', 'AsyncResult']
class
_AbstractLinkable
(
object
):
# Encapsulates the standard parts of the linking and notifying protocol
# common to both repeatable events and one-time events (AsyncRes
o
lt).
# common to both repeatable events and one-time events (AsyncRes
u
lt).
_notifier
=
None
...
...
@@ -63,29 +63,24 @@ class _AbstractLinkable(object):
# Actually call the notification callbacks. Those callbacks in todo that are
# still in _links are called. This method is careful to avoid iterating
# over self._links, because links could be added or removed while this
# method runs. For the same reason, we loop, checking for new items in
# _links.
# method runs. Only links present when this method begins running
# will be called; if a callback adds a new link, it will not run
# until the next time notify_links is activated
# We don't need to capture self._links as todo when establishing
# this callback; any links removed between now and then are handled
# by the `if` below; any links added are also grabbed
todo
=
set
(
self
.
_links
)
done
=
set
()
while
todo
:
for
link
in
todo
:
# check that link was not notified yet and was not removed by the client
# We have to do this here, and not as part of the 'for' statement because
# a previous link(self) call might have altered self._links
if
link
in
self
.
_links
:
try
:
link
(
self
)
except
:
# pylint:disable=bare-except
self
.
hub
.
handle_error
((
link
,
self
),
*
sys
.
exc_info
())
# Mark everything done
done
.
update
(
todo
)
# Anything extra now in self._links but not yet done, loop
# again for
todo
=
self
.
_links
-
done
for
link
in
todo
:
# check that link was not notified yet and was not removed by the client
# We have to do this here, and not as part of the 'for' statement because
# a previous link(self) call might have altered self._links
if
link
in
self
.
_links
:
try
:
link
(
self
)
except
:
# pylint:disable=bare-except
self
.
hub
.
handle_error
((
link
,
self
),
*
sys
.
exc_info
())
def
_wait_core
(
self
,
timeout
,
catch
=
Timeout
):
# The core of the wait implementation, handling
...
...
greentest/test__event.py
View file @
d228edda
...
...
@@ -20,6 +20,39 @@ class TestWaitEvent(greentest.GenericWaitTestCase):
def
wait
(
self
,
timeout
):
gevent
.
wait
([
Event
()],
timeout
=
timeout
)
def
test_set_during_wait
(
self
):
# https://github.com/gevent/gevent/issues/771
# broke in the refactoring. we must not add new links
# while we're running the callback
event
=
Event
()
def
setter
():
event
.
set
()
def
waiter
():
s
=
gevent
.
spawn
(
setter
)
# let the setter set() the event;
# when this method returns we'll be running in the Event._notify_links callback
# (that is, it switched to us)
res
=
event
.
wait
()
self
.
assertTrue
(
res
)
self
.
assertTrue
(
event
.
ready
())
s
.
join
()
# make sure it's dead
# Clear the event. Now we can't wait for the event without
# another set to happen.
event
.
clear
()
self
.
assertFalse
(
event
.
ready
())
# Before the bug fix, this would return "immediately" with
# event in the result list, because the _notify_links loop would
# immediately add the waiter and call it
o
=
gevent
.
wait
((
event
,),
timeout
=
0.01
)
self
.
assertFalse
(
event
.
ready
())
self
.
assertFalse
(
event
in
o
,
o
)
gevent
.
spawn
(
waiter
).
join
()
class
TestAsyncResultWait
(
greentest
.
GenericWaitTestCase
):
...
...
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