Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
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
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
b00b596c
Commit
b00b596c
authored
Apr 22, 2013
by
Serhiy Storchaka
Browse files
Options
Browse Files
Download
Plain Diff
Issue #11714: Use 'with' statements to assure a Semaphore releases a
condition variable. Original patch by Thomas Rachel.
parents
fcd9f222
81a5855a
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
22 additions
and
20 deletions
+22
-20
Lib/threading.py
Lib/threading.py
+18
-20
Misc/ACKS
Misc/ACKS
+1
-0
Misc/NEWS
Misc/NEWS
+3
-0
No files found.
Lib/threading.py
View file @
b00b596c
...
...
@@ -253,31 +253,29 @@ class Semaphore:
raise
ValueError
(
"can't specify timeout for non-blocking acquire"
)
rc
=
False
endtime
=
None
self
.
_cond
.
acquire
()
while
self
.
_value
==
0
:
if
not
blocking
:
break
if
timeout
is
not
None
:
if
endtime
is
None
:
endtime
=
_time
()
+
timeout
else
:
timeout
=
endtime
-
_time
()
if
timeout
<=
0
:
break
self
.
_cond
.
wait
(
timeout
)
else
:
self
.
_value
-=
1
rc
=
True
self
.
_cond
.
release
()
with
self
.
_cond
:
while
self
.
_value
==
0
:
if
not
blocking
:
break
if
timeout
is
not
None
:
if
endtime
is
None
:
endtime
=
_time
()
+
timeout
else
:
timeout
=
endtime
-
_time
()
if
timeout
<=
0
:
break
self
.
_cond
.
wait
(
timeout
)
else
:
self
.
_value
-=
1
rc
=
True
return
rc
__enter__
=
acquire
def
release
(
self
):
self
.
_cond
.
acquire
()
self
.
_value
+=
1
self
.
_cond
.
notify
()
self
.
_cond
.
release
()
with
self
.
_cond
:
self
.
_value
+=
1
self
.
_cond
.
notify
()
def
__exit__
(
self
,
t
,
v
,
tb
):
self
.
release
()
...
...
Misc/ACKS
View file @
b00b596c
...
...
@@ -993,6 +993,7 @@ Fernando Pérez
Pierre Quentel
Brian Quinlan
Anders Qvist
Thomas Rachel
Ram Rachum
Jérôme Radix
Burton Radons
...
...
Misc/NEWS
View file @
b00b596c
...
...
@@ -49,6 +49,9 @@ Core and Builtins
Library
-------
- Issue #11714: Use '
with
' statements to assure a Semaphore releases a
condition variable. Original patch by Thomas Rachel.
- Issue #16624: `subprocess.check_output` now accepts an `input` argument,
allowing the subprocess'
s
stdin
to
be
provided
as
a
(
byte
)
string
.
Patch
by
Zack
Weinberg
.
...
...
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