Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
cpython
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
cpython
Commits
7152f6d9
Kaydet (Commit)
7152f6d9
authored
Nis 02, 2009
tarafından
Jesse Noller
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Add custom initializer argument to multiprocess.Manager*, courtesy of lekma
üst
d56bab47
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
50 additions
and
6 deletions
+50
-6
multiprocessing.rst
Doc/library/multiprocessing.rst
+3
-2
managers.py
Lib/multiprocessing/managers.py
+10
-3
pool.py
Lib/multiprocessing/pool.py
+3
-0
test_multiprocessing.py
Lib/test/test_multiprocessing.py
+31
-1
NEWS
Misc/NEWS
+3
-0
No files found.
Doc/library/multiprocessing.rst
Dosyayı görüntüle @
7152f6d9
...
...
@@ -1130,9 +1130,10 @@ their parent process exits. The manager classes are defined in the
``
current_process
().
authkey
``.
Otherwise
*
authkey
*
is
used
and
it
must
be
a
string
.
..
method
::
start
()
..
method
::
start
(
[
initializer
[,
initargs
]]
)
Start
a
subprocess
to
start
the
manager
.
Start
a
subprocess
to
start
the
manager
.
If
*
initializer
*
is
not
``
None
``
then
the
subprocess
will
call
``
initializer
(*
initargs
)``
when
it
starts
.
..
method
::
serve_forever
()
...
...
Lib/multiprocessing/managers.py
Dosyayı görüntüle @
7152f6d9
...
...
@@ -475,12 +475,15 @@ class BaseManager(object):
dispatch
(
conn
,
None
,
'dummy'
)
self
.
_state
.
value
=
State
.
STARTED
def
start
(
self
):
def
start
(
self
,
initializer
=
None
,
initargs
=
()
):
'''
Spawn a server process for this manager object
'''
assert
self
.
_state
.
value
==
State
.
INITIAL
if
initializer
is
not
None
and
not
hasattr
(
initializer
,
'__call__'
):
raise
TypeError
(
'initializer must be a callable'
)
# pipe over which we will retrieve address of server
reader
,
writer
=
connection
.
Pipe
(
duplex
=
False
)
...
...
@@ -488,7 +491,7 @@ class BaseManager(object):
self
.
_process
=
Process
(
target
=
type
(
self
)
.
_run_server
,
args
=
(
self
.
_registry
,
self
.
_address
,
self
.
_authkey
,
self
.
_serializer
,
writer
),
self
.
_serializer
,
writer
,
initializer
,
initargs
),
)
ident
=
':'
.
join
(
str
(
i
)
for
i
in
self
.
_process
.
_identity
)
self
.
_process
.
name
=
type
(
self
)
.
__name__
+
'-'
+
ident
...
...
@@ -509,10 +512,14 @@ class BaseManager(object):
)
@classmethod
def
_run_server
(
cls
,
registry
,
address
,
authkey
,
serializer
,
writer
):
def
_run_server
(
cls
,
registry
,
address
,
authkey
,
serializer
,
writer
,
initializer
=
None
,
initargs
=
()):
'''
Create a server, report its address and run it
'''
if
initializer
is
not
None
:
initializer
(
*
initargs
)
# create server
server
=
cls
.
_Server
(
registry
,
address
,
authkey
,
serializer
)
...
...
Lib/multiprocessing/pool.py
Dosyayı görüntüle @
7152f6d9
...
...
@@ -92,6 +92,9 @@ class Pool(object):
except
NotImplementedError
:
processes
=
1
if
initializer
is
not
None
and
not
hasattr
(
initializer
,
'__call__'
):
raise
TypeError
(
'initializer must be a callable'
)
self
.
_pool
=
[]
for
i
in
range
(
processes
):
w
=
self
.
Process
(
...
...
Lib/test/test_multiprocessing.py
Dosyayı görüntüle @
7152f6d9
...
...
@@ -1831,7 +1831,37 @@ class OtherTest(unittest.TestCase):
multiprocessing
.
connection
.
answer_challenge
,
_FakeConnection
(),
b
'abc'
)
testcases_other
=
[
OtherTest
,
TestInvalidHandle
]
#
# Test Manager.start()/Pool.__init__() initializer feature - see issue 5585
#
def
initializer
(
ns
):
ns
.
test
+=
1
class
TestInitializers
(
unittest
.
TestCase
):
def
setUp
(
self
):
self
.
mgr
=
multiprocessing
.
Manager
()
self
.
ns
=
self
.
mgr
.
Namespace
()
self
.
ns
.
test
=
0
def
tearDown
(
self
):
self
.
mgr
.
shutdown
()
def
test_manager_initializer
(
self
):
m
=
multiprocessing
.
managers
.
SyncManager
()
self
.
assertRaises
(
TypeError
,
m
.
start
,
1
)
m
.
start
(
initializer
,
(
self
.
ns
,))
self
.
assertEqual
(
self
.
ns
.
test
,
1
)
m
.
shutdown
()
def
test_pool_initializer
(
self
):
self
.
assertRaises
(
TypeError
,
multiprocessing
.
Pool
,
initializer
=
1
)
p
=
multiprocessing
.
Pool
(
1
,
initializer
,
(
self
.
ns
,))
p
.
close
()
p
.
join
()
self
.
assertEqual
(
self
.
ns
.
test
,
1
)
testcases_other
=
[
OtherTest
,
TestInvalidHandle
,
TestInitializers
]
#
#
...
...
Misc/NEWS
Dosyayı görüntüle @
7152f6d9
...
...
@@ -202,6 +202,9 @@ Core and Builtins
Library
-------
- Issue 5585: Add the ability to call an initializer to mulitiprocessing.manager
so that users can install custonm handlers/etc.
- Issue 3551: Patch multiprocessing to raise a proper exception if the size of the
object when writefile is called causes a ERROR_NO_SYSTEM_RESOURCES. Added docs
to note the limitation
...
...
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