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
d194b304
Commit
d194b304
authored
Apr 22, 2013
by
Serhiy Storchaka
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue #11714: Use 'with' statements to assure a Semaphore releases a
condition variable. Original patch by Thomas Rachel.
parent
4dc385b4
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
24 additions
and
22 deletions
+24
-22
Lib/threading.py
Lib/threading.py
+20
-22
Misc/ACKS
Misc/ACKS
+1
-0
Misc/NEWS
Misc/NEWS
+3
-0
No files found.
Lib/threading.py
View file @
d194b304
...
...
@@ -457,21 +457,20 @@ class _Semaphore(_Verbose):
"""
rc
=
False
self
.
__cond
.
acquire
()
while
self
.
__value
==
0
:
if
not
blocking
:
break
if
__debug__
:
self
.
_note
(
"%s.acquire(%s): blocked waiting, value=%s"
,
self
,
blocking
,
self
.
__value
)
self
.
__cond
.
wait
()
else
:
self
.
__value
=
self
.
__value
-
1
if
__debug__
:
self
.
_note
(
"%s.acquire: success, value=%s"
,
self
,
self
.
__value
)
rc
=
True
self
.
__cond
.
release
()
with
self
.
__cond
:
while
self
.
__value
==
0
:
if
not
blocking
:
break
if
__debug__
:
self
.
_note
(
"%s.acquire(%s): blocked waiting, value=%s"
,
self
,
blocking
,
self
.
__value
)
self
.
__cond
.
wait
()
else
:
self
.
__value
=
self
.
__value
-
1
if
__debug__
:
self
.
_note
(
"%s.acquire: success, value=%s"
,
self
,
self
.
__value
)
rc
=
True
return
rc
__enter__
=
acquire
...
...
@@ -483,13 +482,12 @@ class _Semaphore(_Verbose):
to become larger than zero again, wake up that thread.
"""
self
.
__cond
.
acquire
()
self
.
__value
=
self
.
__value
+
1
if
__debug__
:
self
.
_note
(
"%s.release: success, value=%s"
,
self
,
self
.
__value
)
self
.
__cond
.
notify
()
self
.
__cond
.
release
()
with
self
.
__cond
:
self
.
__value
=
self
.
__value
+
1
if
__debug__
:
self
.
_note
(
"%s.release: success, value=%s"
,
self
,
self
.
__value
)
self
.
__cond
.
notify
()
def
__exit__
(
self
,
t
,
v
,
tb
):
self
.
release
()
...
...
Misc/ACKS
View file @
d194b304
...
...
@@ -810,6 +810,7 @@ Fernando Pérez
Eduardo Pérez
Brian Quinlan
Anders Qvist
Thomas Rachel
Burton Radons
Jeff Ramnani
Brodie Rao
...
...
Misc/NEWS
View file @
d194b304
...
...
@@ -28,6 +28,9 @@ Core and Builtins
Library
-------
-
Issue
#
11714
:
Use
'with'
statements
to
assure
a
Semaphore
releases
a
condition
variable
.
Original
patch
by
Thomas
Rachel
.
-
Issue
#
17795
:
Reverted
backwards
-
incompatible
change
in
SysLogHandler
with
Unix
domain
sockets
.
...
...
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