10a8c90248264a8b26970b4473770bcc3df8515fJosh Gao# 20a8c90248264a8b26970b4473770bcc3df8515fJosh Gao# Package analogous to 'threading.py' but using processes 30a8c90248264a8b26970b4473770bcc3df8515fJosh Gao# 40a8c90248264a8b26970b4473770bcc3df8515fJosh Gao# multiprocessing/__init__.py 50a8c90248264a8b26970b4473770bcc3df8515fJosh Gao# 60a8c90248264a8b26970b4473770bcc3df8515fJosh Gao# This package is intended to duplicate the functionality (and much of 70a8c90248264a8b26970b4473770bcc3df8515fJosh Gao# the API) of threading.py but uses processes instead of threads. A 80a8c90248264a8b26970b4473770bcc3df8515fJosh Gao# subpackage 'multiprocessing.dummy' has the same API but is a simple 90a8c90248264a8b26970b4473770bcc3df8515fJosh Gao# wrapper for 'threading'. 100a8c90248264a8b26970b4473770bcc3df8515fJosh Gao# 110a8c90248264a8b26970b4473770bcc3df8515fJosh Gao# Try calling `multiprocessing.doc.main()` to read the html 120a8c90248264a8b26970b4473770bcc3df8515fJosh Gao# documentation in a webbrowser. 130a8c90248264a8b26970b4473770bcc3df8515fJosh Gao# 140a8c90248264a8b26970b4473770bcc3df8515fJosh Gao# 150a8c90248264a8b26970b4473770bcc3df8515fJosh Gao# Copyright (c) 2006-2008, R Oudkerk 160a8c90248264a8b26970b4473770bcc3df8515fJosh Gao# All rights reserved. 170a8c90248264a8b26970b4473770bcc3df8515fJosh Gao# 180a8c90248264a8b26970b4473770bcc3df8515fJosh Gao# Redistribution and use in source and binary forms, with or without 190a8c90248264a8b26970b4473770bcc3df8515fJosh Gao# modification, are permitted provided that the following conditions 200a8c90248264a8b26970b4473770bcc3df8515fJosh Gao# are met: 210a8c90248264a8b26970b4473770bcc3df8515fJosh Gao# 220a8c90248264a8b26970b4473770bcc3df8515fJosh Gao# 1. Redistributions of source code must retain the above copyright 230a8c90248264a8b26970b4473770bcc3df8515fJosh Gao# notice, this list of conditions and the following disclaimer. 240a8c90248264a8b26970b4473770bcc3df8515fJosh Gao# 2. Redistributions in binary form must reproduce the above copyright 250a8c90248264a8b26970b4473770bcc3df8515fJosh Gao# notice, this list of conditions and the following disclaimer in the 260a8c90248264a8b26970b4473770bcc3df8515fJosh Gao# documentation and/or other materials provided with the distribution. 270a8c90248264a8b26970b4473770bcc3df8515fJosh Gao# 3. Neither the name of author nor the names of any contributors may be 280a8c90248264a8b26970b4473770bcc3df8515fJosh Gao# used to endorse or promote products derived from this software 290a8c90248264a8b26970b4473770bcc3df8515fJosh Gao# without specific prior written permission. 300a8c90248264a8b26970b4473770bcc3df8515fJosh Gao# 310a8c90248264a8b26970b4473770bcc3df8515fJosh Gao# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND 320a8c90248264a8b26970b4473770bcc3df8515fJosh Gao# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 330a8c90248264a8b26970b4473770bcc3df8515fJosh Gao# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 340a8c90248264a8b26970b4473770bcc3df8515fJosh Gao# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 350a8c90248264a8b26970b4473770bcc3df8515fJosh Gao# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 360a8c90248264a8b26970b4473770bcc3df8515fJosh Gao# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 370a8c90248264a8b26970b4473770bcc3df8515fJosh Gao# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 380a8c90248264a8b26970b4473770bcc3df8515fJosh Gao# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 390a8c90248264a8b26970b4473770bcc3df8515fJosh Gao# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 400a8c90248264a8b26970b4473770bcc3df8515fJosh Gao# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 410a8c90248264a8b26970b4473770bcc3df8515fJosh Gao# SUCH DAMAGE. 420a8c90248264a8b26970b4473770bcc3df8515fJosh Gao# 430a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 440a8c90248264a8b26970b4473770bcc3df8515fJosh Gao__version__ = '0.70a1' 450a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 460a8c90248264a8b26970b4473770bcc3df8515fJosh Gao__all__ = [ 470a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 'Process', 'current_process', 'active_children', 'freeze_support', 480a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 'Manager', 'Pipe', 'cpu_count', 'log_to_stderr', 'get_logger', 490a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 'allow_connection_pickling', 'BufferTooShort', 'TimeoutError', 500a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 'Lock', 'RLock', 'Semaphore', 'BoundedSemaphore', 'Condition', 510a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 'Event', 'Queue', 'JoinableQueue', 'Pool', 'Value', 'Array', 520a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 'RawValue', 'RawArray', 'SUBDEBUG', 'SUBWARNING', 530a8c90248264a8b26970b4473770bcc3df8515fJosh Gao ] 540a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 550a8c90248264a8b26970b4473770bcc3df8515fJosh Gao__author__ = 'R. Oudkerk (r.m.oudkerk@gmail.com)' 560a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 570a8c90248264a8b26970b4473770bcc3df8515fJosh Gao# 580a8c90248264a8b26970b4473770bcc3df8515fJosh Gao# Imports 590a8c90248264a8b26970b4473770bcc3df8515fJosh Gao# 600a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 610a8c90248264a8b26970b4473770bcc3df8515fJosh Gaoimport os 620a8c90248264a8b26970b4473770bcc3df8515fJosh Gaoimport sys 630a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 640a8c90248264a8b26970b4473770bcc3df8515fJosh Gaofrom multiprocessing.process import Process, current_process, active_children 650a8c90248264a8b26970b4473770bcc3df8515fJosh Gaofrom multiprocessing.util import SUBDEBUG, SUBWARNING 660a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 670a8c90248264a8b26970b4473770bcc3df8515fJosh Gao# 680a8c90248264a8b26970b4473770bcc3df8515fJosh Gao# Exceptions 690a8c90248264a8b26970b4473770bcc3df8515fJosh Gao# 700a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 710a8c90248264a8b26970b4473770bcc3df8515fJosh Gaoclass ProcessError(Exception): 720a8c90248264a8b26970b4473770bcc3df8515fJosh Gao pass 730a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 740a8c90248264a8b26970b4473770bcc3df8515fJosh Gaoclass BufferTooShort(ProcessError): 750a8c90248264a8b26970b4473770bcc3df8515fJosh Gao pass 760a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 770a8c90248264a8b26970b4473770bcc3df8515fJosh Gaoclass TimeoutError(ProcessError): 780a8c90248264a8b26970b4473770bcc3df8515fJosh Gao pass 790a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 800a8c90248264a8b26970b4473770bcc3df8515fJosh Gaoclass AuthenticationError(ProcessError): 810a8c90248264a8b26970b4473770bcc3df8515fJosh Gao pass 820a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 830a8c90248264a8b26970b4473770bcc3df8515fJosh Gao# This is down here because _multiprocessing uses BufferTooShort 840a8c90248264a8b26970b4473770bcc3df8515fJosh Gaoimport _multiprocessing 850a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 860a8c90248264a8b26970b4473770bcc3df8515fJosh Gao# 870a8c90248264a8b26970b4473770bcc3df8515fJosh Gao# Definitions not depending on native semaphores 880a8c90248264a8b26970b4473770bcc3df8515fJosh Gao# 890a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 900a8c90248264a8b26970b4473770bcc3df8515fJosh Gaodef Manager(): 910a8c90248264a8b26970b4473770bcc3df8515fJosh Gao ''' 920a8c90248264a8b26970b4473770bcc3df8515fJosh Gao Returns a manager associated with a running server process 930a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 940a8c90248264a8b26970b4473770bcc3df8515fJosh Gao The managers methods such as `Lock()`, `Condition()` and `Queue()` 950a8c90248264a8b26970b4473770bcc3df8515fJosh Gao can be used to create shared objects. 960a8c90248264a8b26970b4473770bcc3df8515fJosh Gao ''' 970a8c90248264a8b26970b4473770bcc3df8515fJosh Gao from multiprocessing.managers import SyncManager 980a8c90248264a8b26970b4473770bcc3df8515fJosh Gao m = SyncManager() 990a8c90248264a8b26970b4473770bcc3df8515fJosh Gao m.start() 1000a8c90248264a8b26970b4473770bcc3df8515fJosh Gao return m 1010a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 1020a8c90248264a8b26970b4473770bcc3df8515fJosh Gaodef Pipe(duplex=True): 1030a8c90248264a8b26970b4473770bcc3df8515fJosh Gao ''' 1040a8c90248264a8b26970b4473770bcc3df8515fJosh Gao Returns two connection object connected by a pipe 1050a8c90248264a8b26970b4473770bcc3df8515fJosh Gao ''' 1060a8c90248264a8b26970b4473770bcc3df8515fJosh Gao from multiprocessing.connection import Pipe 1070a8c90248264a8b26970b4473770bcc3df8515fJosh Gao return Pipe(duplex) 1080a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 1090a8c90248264a8b26970b4473770bcc3df8515fJosh Gaodef cpu_count(): 1100a8c90248264a8b26970b4473770bcc3df8515fJosh Gao ''' 1110a8c90248264a8b26970b4473770bcc3df8515fJosh Gao Returns the number of CPUs in the system 1120a8c90248264a8b26970b4473770bcc3df8515fJosh Gao ''' 1130a8c90248264a8b26970b4473770bcc3df8515fJosh Gao if sys.platform == 'win32': 1140a8c90248264a8b26970b4473770bcc3df8515fJosh Gao try: 1150a8c90248264a8b26970b4473770bcc3df8515fJosh Gao num = int(os.environ['NUMBER_OF_PROCESSORS']) 1160a8c90248264a8b26970b4473770bcc3df8515fJosh Gao except (ValueError, KeyError): 1170a8c90248264a8b26970b4473770bcc3df8515fJosh Gao num = 0 1180a8c90248264a8b26970b4473770bcc3df8515fJosh Gao elif 'bsd' in sys.platform or sys.platform == 'darwin': 1190a8c90248264a8b26970b4473770bcc3df8515fJosh Gao comm = '/sbin/sysctl -n hw.ncpu' 1200a8c90248264a8b26970b4473770bcc3df8515fJosh Gao if sys.platform == 'darwin': 1210a8c90248264a8b26970b4473770bcc3df8515fJosh Gao comm = '/usr' + comm 1220a8c90248264a8b26970b4473770bcc3df8515fJosh Gao try: 1230a8c90248264a8b26970b4473770bcc3df8515fJosh Gao with os.popen(comm) as p: 1240a8c90248264a8b26970b4473770bcc3df8515fJosh Gao num = int(p.read()) 1250a8c90248264a8b26970b4473770bcc3df8515fJosh Gao except ValueError: 1260a8c90248264a8b26970b4473770bcc3df8515fJosh Gao num = 0 1270a8c90248264a8b26970b4473770bcc3df8515fJosh Gao else: 1280a8c90248264a8b26970b4473770bcc3df8515fJosh Gao try: 1290a8c90248264a8b26970b4473770bcc3df8515fJosh Gao num = os.sysconf('SC_NPROCESSORS_ONLN') 1300a8c90248264a8b26970b4473770bcc3df8515fJosh Gao except (ValueError, OSError, AttributeError): 1310a8c90248264a8b26970b4473770bcc3df8515fJosh Gao num = 0 1320a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 1330a8c90248264a8b26970b4473770bcc3df8515fJosh Gao if num >= 1: 1340a8c90248264a8b26970b4473770bcc3df8515fJosh Gao return num 1350a8c90248264a8b26970b4473770bcc3df8515fJosh Gao else: 1360a8c90248264a8b26970b4473770bcc3df8515fJosh Gao raise NotImplementedError('cannot determine number of cpus') 1370a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 1380a8c90248264a8b26970b4473770bcc3df8515fJosh Gaodef freeze_support(): 1390a8c90248264a8b26970b4473770bcc3df8515fJosh Gao ''' 1400a8c90248264a8b26970b4473770bcc3df8515fJosh Gao Check whether this is a fake forked process in a frozen executable. 1410a8c90248264a8b26970b4473770bcc3df8515fJosh Gao If so then run code specified by commandline and exit. 1420a8c90248264a8b26970b4473770bcc3df8515fJosh Gao ''' 1430a8c90248264a8b26970b4473770bcc3df8515fJosh Gao if sys.platform == 'win32' and getattr(sys, 'frozen', False): 1440a8c90248264a8b26970b4473770bcc3df8515fJosh Gao from multiprocessing.forking import freeze_support 1450a8c90248264a8b26970b4473770bcc3df8515fJosh Gao freeze_support() 1460a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 1470a8c90248264a8b26970b4473770bcc3df8515fJosh Gaodef get_logger(): 1480a8c90248264a8b26970b4473770bcc3df8515fJosh Gao ''' 1490a8c90248264a8b26970b4473770bcc3df8515fJosh Gao Return package logger -- if it does not already exist then it is created 1500a8c90248264a8b26970b4473770bcc3df8515fJosh Gao ''' 1510a8c90248264a8b26970b4473770bcc3df8515fJosh Gao from multiprocessing.util import get_logger 1520a8c90248264a8b26970b4473770bcc3df8515fJosh Gao return get_logger() 1530a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 1540a8c90248264a8b26970b4473770bcc3df8515fJosh Gaodef log_to_stderr(level=None): 1550a8c90248264a8b26970b4473770bcc3df8515fJosh Gao ''' 1560a8c90248264a8b26970b4473770bcc3df8515fJosh Gao Turn on logging and add a handler which prints to stderr 1570a8c90248264a8b26970b4473770bcc3df8515fJosh Gao ''' 1580a8c90248264a8b26970b4473770bcc3df8515fJosh Gao from multiprocessing.util import log_to_stderr 1590a8c90248264a8b26970b4473770bcc3df8515fJosh Gao return log_to_stderr(level) 1600a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 1610a8c90248264a8b26970b4473770bcc3df8515fJosh Gaodef allow_connection_pickling(): 1620a8c90248264a8b26970b4473770bcc3df8515fJosh Gao ''' 1630a8c90248264a8b26970b4473770bcc3df8515fJosh Gao Install support for sending connections and sockets between processes 1640a8c90248264a8b26970b4473770bcc3df8515fJosh Gao ''' 1650a8c90248264a8b26970b4473770bcc3df8515fJosh Gao from multiprocessing import reduction 1660a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 1670a8c90248264a8b26970b4473770bcc3df8515fJosh Gao# 1680a8c90248264a8b26970b4473770bcc3df8515fJosh Gao# Definitions depending on native semaphores 1690a8c90248264a8b26970b4473770bcc3df8515fJosh Gao# 1700a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 1710a8c90248264a8b26970b4473770bcc3df8515fJosh Gaodef Lock(): 1720a8c90248264a8b26970b4473770bcc3df8515fJosh Gao ''' 1730a8c90248264a8b26970b4473770bcc3df8515fJosh Gao Returns a non-recursive lock object 1740a8c90248264a8b26970b4473770bcc3df8515fJosh Gao ''' 1750a8c90248264a8b26970b4473770bcc3df8515fJosh Gao from multiprocessing.synchronize import Lock 1760a8c90248264a8b26970b4473770bcc3df8515fJosh Gao return Lock() 1770a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 1780a8c90248264a8b26970b4473770bcc3df8515fJosh Gaodef RLock(): 1790a8c90248264a8b26970b4473770bcc3df8515fJosh Gao ''' 1800a8c90248264a8b26970b4473770bcc3df8515fJosh Gao Returns a recursive lock object 1810a8c90248264a8b26970b4473770bcc3df8515fJosh Gao ''' 1820a8c90248264a8b26970b4473770bcc3df8515fJosh Gao from multiprocessing.synchronize import RLock 1830a8c90248264a8b26970b4473770bcc3df8515fJosh Gao return RLock() 1840a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 1850a8c90248264a8b26970b4473770bcc3df8515fJosh Gaodef Condition(lock=None): 1860a8c90248264a8b26970b4473770bcc3df8515fJosh Gao ''' 1870a8c90248264a8b26970b4473770bcc3df8515fJosh Gao Returns a condition object 1880a8c90248264a8b26970b4473770bcc3df8515fJosh Gao ''' 1890a8c90248264a8b26970b4473770bcc3df8515fJosh Gao from multiprocessing.synchronize import Condition 1900a8c90248264a8b26970b4473770bcc3df8515fJosh Gao return Condition(lock) 1910a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 1920a8c90248264a8b26970b4473770bcc3df8515fJosh Gaodef Semaphore(value=1): 1930a8c90248264a8b26970b4473770bcc3df8515fJosh Gao ''' 1940a8c90248264a8b26970b4473770bcc3df8515fJosh Gao Returns a semaphore object 1950a8c90248264a8b26970b4473770bcc3df8515fJosh Gao ''' 1960a8c90248264a8b26970b4473770bcc3df8515fJosh Gao from multiprocessing.synchronize import Semaphore 1970a8c90248264a8b26970b4473770bcc3df8515fJosh Gao return Semaphore(value) 1980a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 1990a8c90248264a8b26970b4473770bcc3df8515fJosh Gaodef BoundedSemaphore(value=1): 2000a8c90248264a8b26970b4473770bcc3df8515fJosh Gao ''' 2010a8c90248264a8b26970b4473770bcc3df8515fJosh Gao Returns a bounded semaphore object 2020a8c90248264a8b26970b4473770bcc3df8515fJosh Gao ''' 2030a8c90248264a8b26970b4473770bcc3df8515fJosh Gao from multiprocessing.synchronize import BoundedSemaphore 2040a8c90248264a8b26970b4473770bcc3df8515fJosh Gao return BoundedSemaphore(value) 2050a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 2060a8c90248264a8b26970b4473770bcc3df8515fJosh Gaodef Event(): 2070a8c90248264a8b26970b4473770bcc3df8515fJosh Gao ''' 2080a8c90248264a8b26970b4473770bcc3df8515fJosh Gao Returns an event object 2090a8c90248264a8b26970b4473770bcc3df8515fJosh Gao ''' 2100a8c90248264a8b26970b4473770bcc3df8515fJosh Gao from multiprocessing.synchronize import Event 2110a8c90248264a8b26970b4473770bcc3df8515fJosh Gao return Event() 2120a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 2130a8c90248264a8b26970b4473770bcc3df8515fJosh Gaodef Queue(maxsize=0): 2140a8c90248264a8b26970b4473770bcc3df8515fJosh Gao ''' 2150a8c90248264a8b26970b4473770bcc3df8515fJosh Gao Returns a queue object 2160a8c90248264a8b26970b4473770bcc3df8515fJosh Gao ''' 2170a8c90248264a8b26970b4473770bcc3df8515fJosh Gao from multiprocessing.queues import Queue 2180a8c90248264a8b26970b4473770bcc3df8515fJosh Gao return Queue(maxsize) 2190a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 2200a8c90248264a8b26970b4473770bcc3df8515fJosh Gaodef JoinableQueue(maxsize=0): 2210a8c90248264a8b26970b4473770bcc3df8515fJosh Gao ''' 2220a8c90248264a8b26970b4473770bcc3df8515fJosh Gao Returns a queue object 2230a8c90248264a8b26970b4473770bcc3df8515fJosh Gao ''' 2240a8c90248264a8b26970b4473770bcc3df8515fJosh Gao from multiprocessing.queues import JoinableQueue 2250a8c90248264a8b26970b4473770bcc3df8515fJosh Gao return JoinableQueue(maxsize) 2260a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 2270a8c90248264a8b26970b4473770bcc3df8515fJosh Gaodef Pool(processes=None, initializer=None, initargs=(), maxtasksperchild=None): 2280a8c90248264a8b26970b4473770bcc3df8515fJosh Gao ''' 2290a8c90248264a8b26970b4473770bcc3df8515fJosh Gao Returns a process pool object 2300a8c90248264a8b26970b4473770bcc3df8515fJosh Gao ''' 2310a8c90248264a8b26970b4473770bcc3df8515fJosh Gao from multiprocessing.pool import Pool 2320a8c90248264a8b26970b4473770bcc3df8515fJosh Gao return Pool(processes, initializer, initargs, maxtasksperchild) 2330a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 2340a8c90248264a8b26970b4473770bcc3df8515fJosh Gaodef RawValue(typecode_or_type, *args): 2350a8c90248264a8b26970b4473770bcc3df8515fJosh Gao ''' 2360a8c90248264a8b26970b4473770bcc3df8515fJosh Gao Returns a shared object 2370a8c90248264a8b26970b4473770bcc3df8515fJosh Gao ''' 2380a8c90248264a8b26970b4473770bcc3df8515fJosh Gao from multiprocessing.sharedctypes import RawValue 2390a8c90248264a8b26970b4473770bcc3df8515fJosh Gao return RawValue(typecode_or_type, *args) 2400a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 2410a8c90248264a8b26970b4473770bcc3df8515fJosh Gaodef RawArray(typecode_or_type, size_or_initializer): 2420a8c90248264a8b26970b4473770bcc3df8515fJosh Gao ''' 2430a8c90248264a8b26970b4473770bcc3df8515fJosh Gao Returns a shared array 2440a8c90248264a8b26970b4473770bcc3df8515fJosh Gao ''' 2450a8c90248264a8b26970b4473770bcc3df8515fJosh Gao from multiprocessing.sharedctypes import RawArray 2460a8c90248264a8b26970b4473770bcc3df8515fJosh Gao return RawArray(typecode_or_type, size_or_initializer) 2470a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 2480a8c90248264a8b26970b4473770bcc3df8515fJosh Gaodef Value(typecode_or_type, *args, **kwds): 2490a8c90248264a8b26970b4473770bcc3df8515fJosh Gao ''' 2500a8c90248264a8b26970b4473770bcc3df8515fJosh Gao Returns a synchronized shared object 2510a8c90248264a8b26970b4473770bcc3df8515fJosh Gao ''' 2520a8c90248264a8b26970b4473770bcc3df8515fJosh Gao from multiprocessing.sharedctypes import Value 2530a8c90248264a8b26970b4473770bcc3df8515fJosh Gao return Value(typecode_or_type, *args, **kwds) 2540a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 2550a8c90248264a8b26970b4473770bcc3df8515fJosh Gaodef Array(typecode_or_type, size_or_initializer, **kwds): 2560a8c90248264a8b26970b4473770bcc3df8515fJosh Gao ''' 2570a8c90248264a8b26970b4473770bcc3df8515fJosh Gao Returns a synchronized shared array 2580a8c90248264a8b26970b4473770bcc3df8515fJosh Gao ''' 2590a8c90248264a8b26970b4473770bcc3df8515fJosh Gao from multiprocessing.sharedctypes import Array 2600a8c90248264a8b26970b4473770bcc3df8515fJosh Gao return Array(typecode_or_type, size_or_initializer, **kwds) 2610a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 2620a8c90248264a8b26970b4473770bcc3df8515fJosh Gao# 2630a8c90248264a8b26970b4473770bcc3df8515fJosh Gao# 2640a8c90248264a8b26970b4473770bcc3df8515fJosh Gao# 2650a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 2660a8c90248264a8b26970b4473770bcc3df8515fJosh Gaoif sys.platform == 'win32': 2670a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 2680a8c90248264a8b26970b4473770bcc3df8515fJosh Gao def set_executable(executable): 2690a8c90248264a8b26970b4473770bcc3df8515fJosh Gao ''' 2700a8c90248264a8b26970b4473770bcc3df8515fJosh Gao Sets the path to a python.exe or pythonw.exe binary used to run 2710a8c90248264a8b26970b4473770bcc3df8515fJosh Gao child processes on Windows instead of sys.executable. 2720a8c90248264a8b26970b4473770bcc3df8515fJosh Gao Useful for people embedding Python. 2730a8c90248264a8b26970b4473770bcc3df8515fJosh Gao ''' 2740a8c90248264a8b26970b4473770bcc3df8515fJosh Gao from multiprocessing.forking import set_executable 2750a8c90248264a8b26970b4473770bcc3df8515fJosh Gao set_executable(executable) 2760a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 2770a8c90248264a8b26970b4473770bcc3df8515fJosh Gao __all__ += ['set_executable'] 278