@@ -15,7 +15,9 @@ from multiprocessing.context import (
15
15
from multiprocessing .managers import SyncManager
16
16
from multiprocessing .process import active_children as active_children , current_process as current_process
17
17
18
- # These are technically functions that return instances of these Queue classes. See #4313 for discussion
18
+ # These are technically functions that return instances of these Queue classes.
19
+ # Using them as annotations is deprecated. Either use imports from
20
+ # multiprocessing.queues or the aliases defined below. See #4266 for discussion.
19
21
from multiprocessing .queues import JoinableQueue as JoinableQueue , Queue as Queue , SimpleQueue as SimpleQueue
20
22
from multiprocessing .spawn import freeze_support as freeze_support
21
23
from typing import Any , Optional , Union , overload
@@ -27,6 +29,26 @@ if sys.version_info >= (3, 8):
27
29
if sys .platform != "win32" :
28
30
from multiprocessing .context import ForkContext , ForkServerContext
29
31
32
+ # The following type aliases can be used to annotate the return values of
33
+ # the corresponding functions. They are not defined at runtime.
34
+ #
35
+ # from multiprocessing import Lock
36
+ # from typing import TYPE_CHECKING
37
+ # if TYPE_CHECKING:
38
+ # from multiprocessing import _LockType
39
+ # lock: _LockType = Lock()
40
+
41
+ _QueueType = Queue
42
+ _SimpleQueueType = SimpleQueue
43
+ _JoinableQueueType = JoinableQueue
44
+ _BarrierType = synchronize .Barrier
45
+ _BoundedSemaphoreType = synchronize .BoundedSemaphore
46
+ _ConditionType = synchronize .Condition
47
+ _EventType = synchronize .Event
48
+ _LockType = synchronize .Lock
49
+ _RLockType = synchronize .RLock
50
+ _SemaphoreType = synchronize .Semaphore
51
+
30
52
# N.B. The functions below are generated at runtime by partially applying
31
53
# multiprocessing.context.BaseContext's methods, so the two signatures should
32
54
# be identical (modulo self).
@@ -38,13 +60,13 @@ RawArray = context._default_context.RawArray
38
60
Value = context ._default_context .Value
39
61
Array = context ._default_context .Array
40
62
41
- def Barrier (parties : int , action : Optional [Callable [..., Any ]] = ..., timeout : Optional [float ] = ...) -> synchronize . Barrier : ...
42
- def BoundedSemaphore (value : int = ...) -> synchronize . BoundedSemaphore : ...
43
- def Condition (lock : Optional [_LockLike ] = ...) -> synchronize . Condition : ...
44
- def Event () -> synchronize . Event : ...
45
- def Lock () -> synchronize . Lock : ...
46
- def RLock () -> synchronize . RLock : ...
47
- def Semaphore (value : int = ...) -> synchronize . Semaphore : ...
63
+ def Barrier (parties : int , action : Optional [Callable [..., Any ]] = ..., timeout : Optional [float ] = ...) -> _BarrierType : ...
64
+ def BoundedSemaphore (value : int = ...) -> _BoundedSemaphoreType : ...
65
+ def Condition (lock : Optional [_LockLike ] = ...) -> _ConditionType : ...
66
+ def Event () -> _EventType : ...
67
+ def Lock () -> _LockType : ...
68
+ def RLock () -> _RLockType : ...
69
+ def Semaphore (value : int = ...) -> _SemaphoreType : ...
48
70
def Pipe (duplex : bool = ...) -> tuple [connection .Connection , connection .Connection ]: ...
49
71
def Pool (
50
72
processes : Optional [int ] = ...,
0 commit comments