Back to index

python3.2  3.2.2
Classes | Functions | Variables
multiprocessing.connection Namespace Reference

Classes

class  Listener
class  SocketListener
class  PipeListener
class  ConnectionWrapper
class  XmlListener

Functions

def _init_timeout
def _check_timeout
def arbitrary_address
def address_type
def Client
def Pipe
def SocketClient
def PipeClient
def deliver_challenge
def answer_challenge
def _xml_dumps
def _xml_loads
def XmlClient

Variables

list __all__ = [ 'Client', 'Listener', 'Pipe' ]
int BUFSIZE = 8192
int CONNECTION_TIMEOUT = 20
tuple _mmap_counter = itertools.count()
string default_family = 'AF_INET'
list families = ['AF_INET']
int MESSAGE_LENGTH = 20
string CHALLENGE = '#CHALLENGE#'
string WELCOME = '#WELCOME#'
string FAILURE = '#FAILURE#'

Function Documentation

Definition at line 76 of file connection.py.

00076 
00077 def _check_timeout(t):
00078     return time.time() > t
00079 
00080 #
00081 #
00082 #

Here is the caller graph for this function:

def multiprocessing.connection._init_timeout (   timeout = CONNECTION_TIMEOUT) [private]

Definition at line 73 of file connection.py.

00073 
00074 def _init_timeout(timeout=CONNECTION_TIMEOUT):
00075     return time.time() + timeout

Here is the caller graph for this function:

def multiprocessing.connection._xml_dumps (   obj) [private]

Definition at line 436 of file connection.py.

00436 
00437 def _xml_dumps(obj):
00438     return xmlrpclib.dumps((obj,), None, None, None, 1).encode('utf8')

Definition at line 439 of file connection.py.

00439 
00440 def _xml_loads(s):
00441     (obj,), method = xmlrpclib.loads(s.decode('utf8'))
00442     return obj

Return the types of the address

This can be 'AF_INET', 'AF_UNIX', or 'AF_PIPE'

Definition at line 98 of file connection.py.

00098 
00099 def address_type(address):
00100     '''
00101     Return the types of the address
00102 
00103     This can be 'AF_INET', 'AF_UNIX', or 'AF_PIPE'
00104     '''
00105     if type(address) == tuple:
00106         return 'AF_INET'
00107     elif type(address) is str and address.startswith('\\\\'):
00108         return 'AF_PIPE'
00109     elif type(address) is str:
00110         return 'AF_UNIX'
00111     else:
00112         raise ValueError('address type of %r unrecognized' % address)
00113 
00114 #
00115 # Public functions
00116 #

Here is the caller graph for this function:

def multiprocessing.connection.answer_challenge (   connection,
  authkey 
)

Definition at line 405 of file connection.py.

00405 
00406 def answer_challenge(connection, authkey):
00407     import hmac
00408     assert isinstance(authkey, bytes)
00409     message = connection.recv_bytes(256)         # reject large message
00410     assert message[:len(CHALLENGE)] == CHALLENGE, 'message = %r' % message
00411     message = message[len(CHALLENGE):]
00412     digest = hmac.new(authkey, message).digest()
00413     connection.send_bytes(digest)
00414     response = connection.recv_bytes(256)        # reject large message
00415     if response != WELCOME:
00416         raise AuthenticationError('digest sent was rejected')
00417 
00418 #
00419 # Support for using xmlrpclib for serialization
00420 #

Here is the call graph for this function:

Here is the caller graph for this function:

Return an arbitrary free address for the given family

Definition at line 83 of file connection.py.

00083 
00084 def arbitrary_address(family):
00085     '''
00086     Return an arbitrary free address for the given family
00087     '''
00088     if family == 'AF_INET':
00089         return ('localhost', 0)
00090     elif family == 'AF_UNIX':
00091         return tempfile.mktemp(prefix='listener-', dir=get_temp_dir())
00092     elif family == 'AF_PIPE':
00093         return tempfile.mktemp(prefix=r'\\.\pipe\pyc-%d-%d-' %
00094                                (os.getpid(), next(_mmap_counter)))
00095     else:
00096         raise ValueError('unrecognized family')
00097 

Here is the call graph for this function:

Here is the caller graph for this function:

def multiprocessing.connection.Client (   address,
  family = None,
  authkey = None 
)
Returns a connection to the address of a `Listener`

Definition at line 161 of file connection.py.

00161 
00162 def Client(address, family=None, authkey=None):
00163     '''
00164     Returns a connection to the address of a `Listener`
00165     '''
00166     family = family or address_type(address)
00167     if family == 'AF_PIPE':
00168         c = PipeClient(address)
00169     else:
00170         c = SocketClient(address)
00171 
00172     if authkey is not None and not isinstance(authkey, bytes):
00173         raise TypeError('authkey should be a byte string')
00174 
00175     if authkey is not None:
00176         answer_challenge(c, authkey)
00177         deliver_challenge(c, authkey)
00178 
00179     return c
00180 

Here is the call graph for this function:

Here is the caller graph for this function:

def multiprocessing.connection.deliver_challenge (   connection,
  authkey 
)

Definition at line 392 of file connection.py.

00392 
00393 def deliver_challenge(connection, authkey):
00394     import hmac
00395     assert isinstance(authkey, bytes)
00396     message = os.urandom(MESSAGE_LENGTH)
00397     connection.send_bytes(CHALLENGE + message)
00398     digest = hmac.new(authkey, message).digest()
00399     response = connection.recv_bytes(256)        # reject large message
00400     if response == digest:
00401         connection.send_bytes(WELCOME)
00402     else:
00403         connection.send_bytes(FAILURE)
00404         raise AuthenticationError('digest received was wrong')

Here is the call graph for this function:

Here is the caller graph for this function:

def multiprocessing.connection.Pipe (   duplex = True)
Returns pair of connection objects at either end of a pipe

Definition at line 183 of file connection.py.

00183 
00184     def Pipe(duplex=True):
00185         '''
00186         Returns pair of connection objects at either end of a pipe
00187         '''
00188         if duplex:
00189             s1, s2 = socket.socketpair()
00190             c1 = _multiprocessing.Connection(os.dup(s1.fileno()))
00191             c2 = _multiprocessing.Connection(os.dup(s2.fileno()))
00192             s1.close()
00193             s2.close()
00194         else:
00195             fd1, fd2 = os.pipe()
00196             c1 = _multiprocessing.Connection(fd1, writable=False)
00197             c2 = _multiprocessing.Connection(fd2, readable=False)
00198 
00199         return c1, c2
00200 
00201 else:

Here is the call graph for this function:

Return a connection object connected to the pipe given by `address`

Definition at line 356 of file connection.py.

00356 
00357     def PipeClient(address):
00358         '''
00359         Return a connection object connected to the pipe given by `address`
00360         '''
00361         t = _init_timeout()
00362         while 1:
00363             try:
00364                 win32.WaitNamedPipe(address, 1000)
00365                 h = win32.CreateFile(
00366                     address, win32.GENERIC_READ | win32.GENERIC_WRITE,
00367                     0, win32.NULL, win32.OPEN_EXISTING, 0, win32.NULL
00368                     )
00369             except WindowsError as e:
00370                 if e.args[0] not in (win32.ERROR_SEM_TIMEOUT,
00371                                      win32.ERROR_PIPE_BUSY) or _check_timeout(t):
00372                     raise
00373             else:
00374                 break
00375         else:
00376             raise
00377 
00378         win32.SetNamedPipeHandleState(
00379             h, win32.PIPE_READMODE_MESSAGE, None, None
00380             )
00381         return _multiprocessing.PipeConnection(h)
00382 
00383 #
00384 # Authentication stuff
00385 #

Here is the call graph for this function:

Here is the caller graph for this function:

Return a connection object connected to the socket given by `address`

Definition at line 279 of file connection.py.

00279 
00280 def SocketClient(address):
00281     '''
00282     Return a connection object connected to the socket given by `address`
00283     '''
00284     family = address_type(address)
00285     with socket.socket( getattr(socket, family) ) as s:
00286         t = _init_timeout()
00287 
00288         while 1:
00289             try:
00290                 s.connect(address)
00291             except socket.error as e:
00292                 if e.args[0] != errno.ECONNREFUSED or _check_timeout(t):
00293                     debug('failed to connect to address %s', address)
00294                     raise
00295                 time.sleep(0.01)
00296             else:
00297                 break
00298         else:
00299             raise
00300 
00301         fd = duplicate(s.fileno())
00302     conn = _multiprocessing.Connection(fd)
00303     return conn
00304 
00305 #
00306 # Definitions for connections based on named pipes
00307 #

Here is the call graph for this function:

Here is the caller graph for this function:

def multiprocessing.connection.XmlClient (   args,
  kwds 
)

Definition at line 450 of file connection.py.

00450 
00451 def XmlClient(*args, **kwds):
00452     global xmlrpclib
00453     import xmlrpc.client as xmlrpclib
00454     return ConnectionWrapper(Client(*args, **kwds), _xml_dumps, _xml_loads)

Here is the call graph for this function:


Variable Documentation

Definition at line 35 of file connection.py.

Definition at line 59 of file connection.py.

Definition at line 55 of file connection.py.

Definition at line 388 of file connection.py.

Definition at line 57 of file connection.py.

Definition at line 61 of file connection.py.

Definition at line 390 of file connection.py.

Definition at line 62 of file connection.py.

Definition at line 386 of file connection.py.

Definition at line 389 of file connection.py.