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
e428bb70
Commit
e428bb70
authored
Aug 20, 2001
by
Skip Montanaro
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added new BoundedSemaphore class. Closes bug 452836.
parent
a7fc21ba
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
15 additions
and
0 deletions
+15
-0
Lib/threading.py
Lib/threading.py
+15
-0
No files found.
Lib/threading.py
View file @
e428bb70
...
...
@@ -284,6 +284,21 @@ class _Semaphore(_Verbose):
self
.
__cond
.
release
()
def
BoundedSemaphore
(
*
args
,
**
kwargs
):
return
apply
(
_BoundedSemaphore
,
args
,
kwargs
)
class
_BoundedSemaphore
(
_Semaphore
):
"""Semaphore that checks that # releases is <= # acquires"""
def
__init__
(
self
,
value
=
1
,
verbose
=
None
):
_Semaphore
.
__init__
(
self
,
value
,
verbose
)
self
.
_initial_value
=
value
def
release
(
self
):
if
self
.
_Semaphore__value
>=
self
.
_initial_value
:
raise
ValueError
,
"Semaphore released too many times"
return
_Semaphore
.
release
(
self
)
def
Event
(
*
args
,
**
kwargs
):
return
apply
(
_Event
,
args
,
kwargs
)
...
...
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