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
3730a17a
Commit
3730a17a
authored
Jun 15, 2012
by
Richard Oudkerk
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue #14059: Implement multiprocessing.Barrier
parent
a6bc4b4c
Changes
7
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
426 additions
and
12 deletions
+426
-12
Doc/library/multiprocessing.rst
Doc/library/multiprocessing.rst
+18
-5
Lib/multiprocessing/__init__.py
Lib/multiprocessing/__init__.py
+9
-2
Lib/multiprocessing/dummy/__init__.py
Lib/multiprocessing/dummy/__init__.py
+2
-2
Lib/multiprocessing/managers.py
Lib/multiprocessing/managers.py
+21
-0
Lib/multiprocessing/synchronize.py
Lib/multiprocessing/synchronize.py
+40
-0
Lib/test/test_multiprocessing.py
Lib/test/test_multiprocessing.py
+334
-3
Misc/NEWS
Misc/NEWS
+2
-0
No files found.
Doc/library/multiprocessing.rst
View file @
3730a17a
...
...
@@ -226,11 +226,11 @@ However, if you really do need to use some shared data then
holds Python objects and allows other processes to manipulate them using
proxies.
A manager returned by :func:`Manager` will support types
:class:`list`,
:class:`
dict`, :class:`Namespace`, :class:`Lock`, :class:`R
Lock`,
:class:`
Semaphore`, :class:`BoundedSemaphore`, :class:`Condition
`,
:class:`
Event`, :class:`Queue`, :class:`Value` and :class:`Array`. For
example, ::
A manager returned by :func:`Manager` will support types
:class:`
list`, :class:`dict`, :class:`Namespace`, :class:`
Lock`,
:class:`
RLock`, :class:`Semaphore`, :class:`BoundedSemaphore
`,
:class:`
Condition`, :class:`Event`, :class:`Barrier`,
:class:`Queue`, :class:`Value` and :class:`Array`. For
example, ::
from multiprocessing import Process, Manager
...
...
@@ -885,6 +885,12 @@ program as they are in a multithreaded program. See the documentation for
Note
that
one
can
also
create
synchronization
primitives
by
using
a
manager
object
--
see
:
ref
:`
multiprocessing
-
managers
`.
..
class
::
Barrier
(
parties
[,
action
[,
timeout
]])
A
barrier
object
:
a
clone
of
:
class
:`
threading
.
Barrier
`.
..
versionadded
::
3.3
..
class
::
BoundedSemaphore
([
value
])
A
bounded
semaphore
object
:
a
clone
of
:
class
:`
threading
.
BoundedSemaphore
`.
...
...
@@ -1280,6 +1286,13 @@ their parent process exits. The manager classes are defined in the
It
also
supports
creation
of
shared
lists
and
dictionaries
.
..
method
::
Barrier
(
parties
[,
action
[,
timeout
]])
Create
a
shared
:
class
:`
threading
.
Barrier
`
object
and
return
a
proxy
for
it
.
..
versionadded
::
3.3
..
method
::
BoundedSemaphore
([
value
])
Create
a
shared
:
class
:`
threading
.
BoundedSemaphore
`
object
and
return
a
...
...
Lib/multiprocessing/__init__.py
View file @
3730a17a
...
...
@@ -23,8 +23,8 @@ __all__ = [
'Manager'
,
'Pipe'
,
'cpu_count'
,
'log_to_stderr'
,
'get_logger'
,
'allow_connection_pickling'
,
'BufferTooShort'
,
'TimeoutError'
,
'Lock'
,
'RLock'
,
'Semaphore'
,
'BoundedSemaphore'
,
'Condition'
,
'Event'
,
'
Queue'
,
'SimpleQueue'
,
'JoinableQueue'
,
'Pool'
,
'Value'
,
'Array
'
,
'RawValue'
,
'RawArray'
,
'SUBDEBUG'
,
'SUBWARNING'
,
'Event'
,
'
Barrier'
,
'Queue'
,
'SimpleQueue'
,
'JoinableQueue'
,
'Pool
'
,
'
Value'
,
'Array'
,
'
RawValue'
,
'RawArray'
,
'SUBDEBUG'
,
'SUBWARNING'
,
]
__author__
=
'R. Oudkerk (r.m.oudkerk@gmail.com)'
...
...
@@ -186,6 +186,13 @@ def Event():
from
multiprocessing.synchronize
import
Event
return
Event
()
def
Barrier
(
parties
,
action
=
None
,
timeout
=
None
):
'''
Returns a barrier object
'''
from
multiprocessing.synchronize
import
Barrier
return
Barrier
(
parties
,
action
,
timeout
)
def
Queue
(
maxsize
=
0
):
'''
Returns a queue object
...
...
Lib/multiprocessing/dummy/__init__.py
View file @
3730a17a
...
...
@@ -35,7 +35,7 @@
__all__
=
[
'Process'
,
'current_process'
,
'active_children'
,
'freeze_support'
,
'Lock'
,
'RLock'
,
'Semaphore'
,
'BoundedSemaphore'
,
'Condition'
,
'Event'
,
'Queue'
,
'Manager'
,
'Pipe'
,
'Pool'
,
'JoinableQueue'
'Event'
,
'
Barrier'
,
'
Queue'
,
'Manager'
,
'Pipe'
,
'Pool'
,
'JoinableQueue'
]
#
...
...
@@ -49,7 +49,7 @@ import array
from
multiprocessing.dummy.connection
import
Pipe
from
threading
import
Lock
,
RLock
,
Semaphore
,
BoundedSemaphore
from
threading
import
Event
,
Condition
from
threading
import
Event
,
Condition
,
Barrier
from
queue
import
Queue
#
...
...
Lib/multiprocessing/managers.py
View file @
3730a17a
...
...
@@ -993,6 +993,26 @@ class EventProxy(BaseProxy):
def
wait
(
self
,
timeout
=
None
):
return
self
.
_callmethod
(
'wait'
,
(
timeout
,))
class
BarrierProxy
(
BaseProxy
):
_exposed_
=
(
'__getattribute__'
,
'wait'
,
'abort'
,
'reset'
)
def
wait
(
self
,
timeout
=
None
):
return
self
.
_callmethod
(
'wait'
,
(
timeout
,))
def
abort
(
self
):
return
self
.
_callmethod
(
'abort'
)
def
reset
(
self
):
return
self
.
_callmethod
(
'reset'
)
@
property
def
parties
(
self
):
return
self
.
_callmethod
(
'__getattribute__'
,
(
'parties'
,))
@
property
def
n_waiting
(
self
):
return
self
.
_callmethod
(
'__getattribute__'
,
(
'n_waiting'
,))
@
property
def
broken
(
self
):
return
self
.
_callmethod
(
'__getattribute__'
,
(
'broken'
,))
class
NamespaceProxy
(
BaseProxy
):
_exposed_
=
(
'__getattribute__'
,
'__setattr__'
,
'__delattr__'
)
def
__getattr__
(
self
,
key
):
...
...
@@ -1084,6 +1104,7 @@ SyncManager.register('Semaphore', threading.Semaphore, AcquirerProxy)
SyncManager
.
register
(
'BoundedSemaphore'
,
threading
.
BoundedSemaphore
,
AcquirerProxy
)
SyncManager
.
register
(
'Condition'
,
threading
.
Condition
,
ConditionProxy
)
SyncManager
.
register
(
'Barrier'
,
threading
.
Barrier
,
BarrierProxy
)
SyncManager
.
register
(
'Pool'
,
Pool
,
PoolProxy
)
SyncManager
.
register
(
'list'
,
list
,
ListProxy
)
SyncManager
.
register
(
'dict'
,
dict
,
DictProxy
)
...
...
Lib/multiprocessing/synchronize.py
View file @
3730a17a
...
...
@@ -333,3 +333,43 @@ class Event(object):
return
False
finally
:
self
.
_cond
.
release
()
#
# Barrier
#
class
Barrier
(
threading
.
Barrier
):
def
__init__
(
self
,
parties
,
action
=
None
,
timeout
=
None
):
import
struct
from
multiprocessing.heap
import
BufferWrapper
wrapper
=
BufferWrapper
(
struct
.
calcsize
(
'i'
)
*
2
)
cond
=
Condition
()
self
.
__setstate__
((
parties
,
action
,
timeout
,
cond
,
wrapper
))
self
.
_state
=
0
self
.
_count
=
0
def
__setstate__
(
self
,
state
):
(
self
.
_parties
,
self
.
_action
,
self
.
_timeout
,
self
.
_cond
,
self
.
_wrapper
)
=
state
self
.
_array
=
self
.
_wrapper
.
create_memoryview
().
cast
(
'i'
)
def
__getstate__
(
self
):
return
(
self
.
_parties
,
self
.
_action
,
self
.
_timeout
,
self
.
_cond
,
self
.
_wrapper
)
@
property
def
_state
(
self
):
return
self
.
_array
[
0
]
@
_state
.
setter
def
_state
(
self
,
value
):
self
.
_array
[
0
]
=
value
@
property
def
_count
(
self
):
return
self
.
_array
[
1
]
@
_count
.
setter
def
_count
(
self
,
value
):
self
.
_array
[
1
]
=
value
Lib/test/test_multiprocessing.py
View file @
3730a17a
This diff is collapsed.
Click to expand it.
Misc/NEWS
View file @
3730a17a
...
...
@@ -21,6 +21,8 @@ Core and Builtins
Library
-------
- Issue #14059: Implement multiprocessing.Barrier.
- Issue #15061: The inappropriately named hmac.secure_compare has been
renamed to hmac.compare_digest, restricted to operating on bytes inputs
only and had its documentation updated to more accurately reflect both its
...
...
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