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
59a537fe
Commit
59a537fe
authored
Mar 23, 2018
by
Jason Madden
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Avoid a circular ref that broke the leaktests. Bonus: it's actually faster on Py3
parent
50a3130b
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
12 additions
and
20 deletions
+12
-20
src/gevent/_threading.py
src/gevent/_threading.py
+12
-20
No files found.
src/gevent/_threading.py
View file @
59a537fe
...
...
@@ -29,6 +29,7 @@ class _Condition(object):
def
__init__
(
self
,
lock
):
self
.
__lock
=
lock
self
.
__waiters
=
[]
# If the lock defines _release_save() and/or _acquire_restore(),
# these override the default implementations (which just call
...
...
@@ -45,17 +46,12 @@ class _Condition(object):
self
.
_is_owned
=
lock
.
_is_owned
except
AttributeError
:
pass
self
.
__waiters
=
[]
# Capture the bound method to save some time returning it
self
.
__notify_one
=
self
.
_notify_one
self
.
__wait
=
self
.
_wait
def
__enter__
(
self
):
self
.
__lock
.
__enter__
()
return
self
.
__wait
,
self
.
__notify_one
return
self
.
__lock
.
__enter__
()
def
__exit__
(
self
,
*
args
):
return
self
.
__lock
.
__exit__
(
*
args
)
def
__exit__
(
self
,
t
,
v
,
tb
):
return
self
.
__lock
.
__exit__
(
t
,
v
,
tb
)
def
__repr__
(
self
):
return
"<Condition(%s, %d)>"
%
(
self
.
__lock
,
len
(
self
.
__waiters
))
...
...
@@ -74,10 +70,8 @@ class _Condition(object):
return
False
return
True
def
_wait
(
self
):
# The condition MUST be owned; the only way to get this
# method is through __enter__, so it is guaranteed and we don't
# need to check it.
def
wait
(
self
):
# The condition MUST be owned, but we don't check that.
waiter
=
Lock
()
waiter
.
acquire
()
self
.
__waiters
.
append
(
waiter
)
...
...
@@ -87,10 +81,8 @@ class _Condition(object):
finally
:
self
.
_acquire_restore
(
saved_state
)
def
_notify_one
(
self
):
# The condition MUST be owned; the only way to get this
# method is through __enter__, so it is guaranteed and we
# don't need to check it.
def
notify_one
(
self
):
# The condition MUST be owned, but we don't check that.
try
:
waiter
=
self
.
__waiters
.
pop
()
except
IndexError
:
...
...
@@ -157,16 +149,16 @@ class Queue(object):
def
put
(
self
,
item
):
"""Put an item into the queue.
"""
with
self
.
_not_empty
as
(
_
,
notify_one
)
:
with
self
.
_not_empty
:
self
.
_queue
.
append
(
item
)
self
.
unfinished_tasks
+=
1
notify_one
()
self
.
_not_empty
.
notify_one
()
def
get
(
self
):
"""Remove and return an item from the queue.
"""
with
self
.
_not_empty
as
(
wait
,
_
)
:
with
self
.
_not_empty
:
while
not
self
.
_queue
:
wait
()
self
.
_not_empty
.
wait
()
item
=
self
.
_queue
.
popleft
()
return
item
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