]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Submit Nick's patch for issue 3589, reviewed by jnoller
authorJesse Noller <jnoller@gmail.com>
Mon, 1 Sep 2008 16:47:25 +0000 (16:47 +0000)
committerJesse Noller <jnoller@gmail.com>
Mon, 1 Sep 2008 16:47:25 +0000 (16:47 +0000)
Lib/multiprocessing/__init__.py
Lib/multiprocessing/sharedctypes.py
Lib/multiprocessing/synchronize.py
Lib/multiprocessing/util.py

index f96505630ae5487a4a326bd8907adb0d75f2edeb..c0fa1fccbe129d81d0c25bd8cd926d7beef70aeb 100644 (file)
@@ -97,13 +97,6 @@ def Manager():
     m.start()
     return m
 
-def Pipe(duplex=True):
-    '''
-    Returns two connection object connected by a pipe
-    '''
-    from multiprocessing.connection import Pipe
-    return Pipe(duplex)
-
 def cpu_count():
     '''
     Returns the number of CPUs in the system
@@ -138,134 +131,28 @@ def freeze_support():
         from multiprocessing.forking import freeze_support
         freeze_support()
 
-def get_logger():
-    '''
-    Return package logger -- if it does not already exist then it is created
-    '''
-    from multiprocessing.util import get_logger
-    return get_logger()
-
-def log_to_stderr(level=None):
-    '''
-    Turn on logging and add a handler which prints to stderr
-    '''
-    from multiprocessing.util import log_to_stderr
-    return log_to_stderr(level)
-
 def allow_connection_pickling():
     '''
     Install support for sending connections and sockets between processes
     '''
     from multiprocessing import reduction
 
-#
-# Definitions depending on native semaphores
-#
-
-def Lock():
-    '''
-    Returns a non-recursive lock object
-    '''
-    from multiprocessing.synchronize import Lock
-    return Lock()
-
-def RLock():
-    '''
-    Returns a recursive lock object
-    '''
-    from multiprocessing.synchronize import RLock
-    return RLock()
-
-def Condition(lock=None):
-    '''
-    Returns a condition object
-    '''
-    from multiprocessing.synchronize import Condition
-    return Condition(lock)
-
-def Semaphore(value=1):
-    '''
-    Returns a semaphore object
-    '''
-    from multiprocessing.synchronize import Semaphore
-    return Semaphore(value)
-
-def BoundedSemaphore(value=1):
-    '''
-    Returns a bounded semaphore object
-    '''
-    from multiprocessing.synchronize import BoundedSemaphore
-    return BoundedSemaphore(value)
-
-def Event():
-    '''
-    Returns an event object
-    '''
-    from multiprocessing.synchronize import Event
-    return Event()
-
-def Queue(maxsize=0):
-    '''
-    Returns a queue object
-    '''
-    from multiprocessing.queues import Queue
-    return Queue(maxsize)
-
-def JoinableQueue(maxsize=0):
-    '''
-    Returns a queue object
-    '''
-    from multiprocessing.queues import JoinableQueue
-    return JoinableQueue(maxsize)
-
-def Pool(processes=None, initializer=None, initargs=()):
-    '''
-    Returns a process pool object
-    '''
-    from multiprocessing.pool import Pool
-    return Pool(processes, initializer, initargs)
-
-def RawValue(typecode_or_type, *args):
-    '''
-    Returns a shared object
-    '''
-    from multiprocessing.sharedctypes import RawValue
-    return RawValue(typecode_or_type, *args)
-
-def RawArray(typecode_or_type, size_or_initializer):
-    '''
-    Returns a shared array
-    '''
-    from multiprocessing.sharedctypes import RawArray
-    return RawArray(typecode_or_type, size_or_initializer)
-
-def Value(typecode_or_type, *args, **kwds):
-    '''
-    Returns a synchronized shared object
-    '''
-    from multiprocessing.sharedctypes import Value
-    return Value(typecode_or_type, *args, **kwds)
-
-def Array(typecode_or_type, size_or_initializer, **kwds):
-    '''
-    Returns a synchronized shared array
-    '''
-    from multiprocessing.sharedctypes import Array
-    return Array(typecode_or_type, size_or_initializer, **kwds)
+# Alias some names from submodules in the package namespace
+from multiprocessing.connection import Pipe
+from multiprocessing.util import (get_logger, log_to_stderr)
 
 #
+# Definitions depending on native semaphores
 #
-#
+# Alias some names from submodules in the package namespace
+from multiprocessing.synchronize import (Lock, RLock, Condition, Event,
+                                         Semaphore, BoundedSemaphore)
+from multiprocessing.queues import (Queue, JoinableQueue)
+from multiprocessing.pool import Pool
+from multiprocessing.sharedctypes import (RawValue, Value,
+                                          RawArray, Array)
 
 if sys.platform == 'win32':
-
-    def set_executable(executable):
-        '''
-        Sets the path to a python.exe or pythonw.exe binary used to run
-        child processes on Windows instead of sys.executable.
-        Useful for people embedding Python.
-        '''
-        from multiprocessing.forking import set_executable
-        set_executable(executable)
+    from multiprocessing.forking import set_executable
 
     __all__ += ['set_executable']
index 0054ff1822e5b7b824a6b3b20225bf203f052586..5ca8fb8bfbc21483e4ae36de6939885daf0867c3 100644 (file)
@@ -63,7 +63,7 @@ def RawArray(typecode_or_type, size_or_initializer):
 
 def Value(typecode_or_type, *args, **kwds):
     '''
-    Return a synchronization wrapper for a Value
+    Return a synchronization wrapper for a RawValue
     '''
     lock = kwds.pop('lock', None)
     if kwds:
index 428656a5b15d5c8f35e66409672144fc4331acb3..3e21dfec853a190d7e68d6002505382f82e61d9c 100644 (file)
@@ -65,7 +65,9 @@ class SemLock(object):
 #
 
 class Semaphore(SemLock):
-
+    '''
+    A semaphore object
+    '''
     def __init__(self, value=1):
         SemLock.__init__(self, SEMAPHORE, value, SEM_VALUE_MAX)
 
@@ -84,7 +86,9 @@ class Semaphore(SemLock):
 #
 
 class BoundedSemaphore(Semaphore):
-
+    '''
+    A bounded semaphore object
+    '''
     def __init__(self, value=1):
         SemLock.__init__(self, SEMAPHORE, value, value)
 
@@ -101,7 +105,9 @@ class BoundedSemaphore(Semaphore):
 #
 
 class Lock(SemLock):
-
+    '''
+    A non-recursive lock object
+    '''
     def __init__(self):
         SemLock.__init__(self, SEMAPHORE, 1, 1)
 
@@ -126,7 +132,9 @@ class Lock(SemLock):
 #
 
 class RLock(SemLock):
-
+    '''
+    A recursive lock object
+    '''
     def __init__(self):
         SemLock.__init__(self, RECURSIVE_MUTEX, 1, 1)
 
@@ -152,6 +160,9 @@ class RLock(SemLock):
 #
 
 class Condition(object):
+    '''
+    A condition object
+    '''
 
     def __init__(self, lock=None):
         self._lock = lock or RLock()
@@ -252,7 +263,9 @@ class Condition(object):
 #
 
 class Event(object):
-
+    '''
+    An event object
+    '''
     def __init__(self):
         self._cond = Condition(Lock())
         self._flag = Semaphore(0)
index 7d53512725c77bcfcbeba0929ae33d474df2e65d..c3e811c4dadefaddc770c6971e15d000fdede858 100644 (file)
@@ -54,7 +54,7 @@ def sub_warning(msg, *args):
 
 def get_logger():
     '''
-    Returns logger used by multiprocessing
+    Return package logger -- if it does not already exist then it is created
     '''
     global _logger