当前位置: 首页>>代码示例>>Python>>正文


Python multiprocessing.connection方法代码示例

本文整理汇总了Python中multiprocessing.connection方法的典型用法代码示例。如果您正苦于以下问题:Python multiprocessing.connection方法的具体用法?Python multiprocessing.connection怎么用?Python multiprocessing.connection使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在multiprocessing的用法示例。


在下文中一共展示了multiprocessing.connection方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: startEventLoop

# 需要导入模块: import multiprocessing [as 别名]
# 或者: from multiprocessing import connection [as 别名]
def startEventLoop(name, port, authkey, ppid, debug=False):
    if debug:
        import os
        cprint.cout(debug, '[%d] connecting to server at port localhost:%d, authkey=%s..\n' 
                    % (os.getpid(), port, repr(authkey)), -1)
    conn = multiprocessing.connection.Client(('localhost', int(port)), authkey=authkey)
    if debug:
        cprint.cout(debug, '[%d] connected; starting remote proxy.\n' % os.getpid(), -1)
    global HANDLER
    #ppid = 0 if not hasattr(os, 'getppid') else os.getppid()
    HANDLER = RemoteEventHandler(conn, name, ppid, debug=debug)
    while True:
        try:
            HANDLER.processRequests()  # exception raised when the loop should exit
            time.sleep(0.01)
        except ClosedError:
            HANDLER.debugMsg('Exiting server loop.')
            sys.exit(0) 
开发者ID:SrikanthVelpuri,项目名称:tf-pose,代码行数:20,代码来源:processes.py

示例2: startQtEventLoop

# 需要导入模块: import multiprocessing [as 别名]
# 或者: from multiprocessing import connection [as 别名]
def startQtEventLoop(name, port, authkey, ppid, debug=False):
    if debug:
        import os
        cprint.cout(debug, '[%d] connecting to server at port localhost:%d, authkey=%s..\n' % (os.getpid(), port, repr(authkey)), -1)
    conn = multiprocessing.connection.Client(('localhost', int(port)), authkey=authkey)
    if debug:
        cprint.cout(debug, '[%d] connected; starting remote proxy.\n' % os.getpid(), -1)
    from ..Qt import QtGui, QtCore
    app = QtGui.QApplication.instance()
    #print app
    if app is None:
        app = QtGui.QApplication([])
        app.setQuitOnLastWindowClosed(False)  ## generally we want the event loop to stay open 
                                              ## until it is explicitly closed by the parent process.
    
    global HANDLER
    HANDLER = RemoteQtEventHandler(conn, name, ppid, debug=debug)
    HANDLER.startEventTimer()
    app.exec_() 
开发者ID:SrikanthVelpuri,项目名称:tf-pose,代码行数:21,代码来源:processes.py

示例3: test_spawn_close

# 需要导入模块: import multiprocessing [as 别名]
# 或者: from multiprocessing import connection [as 别名]
def test_spawn_close(self):
        # We test that a pipe connection can be closed by parent
        # process immediately after child is spawned.  On Windows this
        # would have sometimes failed on old versions because
        # child_conn would be closed before the child got a chance to
        # duplicate it.
        conn, child_conn = self.Pipe()

        p = self.Process(target=self._echo, args=(child_conn,))
        p.daemon = True
        p.start()
        child_conn.close()    # this might complete before child initializes

        msg = latin('hello')
        conn.send_bytes(msg)
        self.assertEqual(conn.recv_bytes(), msg)

        conn.send_bytes(SENTINEL)
        conn.close()
        p.join() 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:22,代码来源:test_multiprocessing.py

示例4: test_issue14725

# 需要导入模块: import multiprocessing [as 别名]
# 或者: from multiprocessing import connection [as 别名]
def test_issue14725(self):
        l = self.connection.Listener()
        p = self.Process(target=self._test, args=(l.address,))
        p.daemon = True
        p.start()
        time.sleep(1)
        # On Windows the client process should by now have connected,
        # written data and closed the pipe handle by now.  This causes
        # ConnectNamdedPipe() to fail with ERROR_NO_DATA.  See Issue
        # 14725.
        conn = l.accept()
        self.assertEqual(conn.recv(), 'hello')
        conn.close()
        p.join()
        l.close()

#
# Test of sending connection and socket objects between processes
# 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:21,代码来源:test_multiprocessing.py

示例5: test_answer_challenge_auth_failure

# 需要导入模块: import multiprocessing [as 别名]
# 或者: from multiprocessing import connection [as 别名]
def test_answer_challenge_auth_failure(self):
        class _FakeConnection(object):
            def __init__(self):
                self.count = 0
            def recv_bytes(self, size):
                self.count += 1
                if self.count == 1:
                    return multiprocessing.connection.CHALLENGE
                elif self.count == 2:
                    return b'something bogus'
                return b''
            def send_bytes(self, data):
                pass
        self.assertRaises(multiprocessing.AuthenticationError,
                          multiprocessing.connection.answer_challenge,
                          _FakeConnection(), b'abc')

#
# Test Manager.start()/Pool.__init__() initializer feature - see issue 5585
# 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:22,代码来源:test_multiprocessing.py

示例6: test_timeout

# 需要导入模块: import multiprocessing [as 别名]
# 或者: from multiprocessing import connection [as 别名]
def test_timeout(self):
        old_timeout = socket.getdefaulttimeout()
        try:
            socket.setdefaulttimeout(0.1)
            parent, child = multiprocessing.Pipe(duplex=True)
            l = multiprocessing.connection.Listener(family='AF_INET')
            p = multiprocessing.Process(target=self._test_timeout,
                                        args=(child, l.address))
            p.start()
            child.close()
            self.assertEqual(parent.recv(), 123)
            parent.close()
            conn = l.accept()
            self.assertEqual(conn.recv(), 456)
            conn.close()
            l.close()
            p.join(10)
        finally:
            socket.setdefaulttimeout(old_timeout)

#
# Test what happens with no "if __name__ == '__main__'"
# 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:25,代码来源:test_multiprocessing.py

示例7: test_dont_merge

# 需要导入模块: import multiprocessing [as 别名]
# 或者: from multiprocessing import connection [as 别名]
def test_dont_merge(self):
        a, b = self.Pipe()
        self.assertEqual(a.poll(0.0), False)
        self.assertEqual(a.poll(0.1), False)

        p = self.Process(target=self._child_dont_merge, args=(b,))
        p.start()

        self.assertEqual(a.recv_bytes(), b'a')
        self.assertEqual(a.poll(1.0), True)
        self.assertEqual(a.poll(1.0), True)
        self.assertEqual(a.recv_bytes(), b'b')
        self.assertEqual(a.poll(1.0), True)
        self.assertEqual(a.poll(1.0), True)
        self.assertEqual(a.poll(0.0), True)
        self.assertEqual(a.recv_bytes(), b'cd')

        p.join()

#
# Test of sending connection and socket objects between processes
# 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:24,代码来源:_test_multiprocessing.py

示例8: _listener

# 需要导入模块: import multiprocessing [as 别名]
# 或者: from multiprocessing import connection [as 别名]
def _listener(cls, conn, families):
        for fam in families:
            l = cls.connection.Listener(family=fam)
            conn.send(l.address)
            new_conn = l.accept()
            conn.send(new_conn)
            new_conn.close()
            l.close()

        l = socket.socket()
        l.bind((test.support.HOST, 0))
        l.listen()
        conn.send(l.getsockname())
        new_conn, addr = l.accept()
        conn.send(new_conn)
        new_conn.close()
        l.close()

        conn.recv() 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:21,代码来源:_test_multiprocessing.py

示例9: test_ignore_listener

# 需要导入模块: import multiprocessing [as 别名]
# 或者: from multiprocessing import connection [as 别名]
def test_ignore_listener(self):
        conn, child_conn = multiprocessing.Pipe()
        try:
            p = multiprocessing.Process(target=self._test_ignore_listener,
                                        args=(child_conn,))
            p.daemon = True
            p.start()
            child_conn.close()
            address = conn.recv()
            time.sleep(0.1)
            os.kill(p.pid, signal.SIGUSR1)
            time.sleep(0.1)
            client = multiprocessing.connection.Client(address)
            self.assertEqual(client.recv(), 'welcome')
            p.join()
        finally:
            conn.close() 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:19,代码来源:_test_multiprocessing.py

示例10: _listener

# 需要导入模块: import multiprocessing [as 别名]
# 或者: from multiprocessing import connection [as 别名]
def _listener(cls, conn, families):
        for fam in families:
            l = cls.connection.Listener(family=fam)
            conn.send(l.address)
            new_conn = l.accept()
            conn.send(new_conn)
            new_conn.close()
            l.close()

        l = socket.socket()
        l.bind((test.support.HOST, 0))
        l.listen(1)
        conn.send(l.getsockname())
        new_conn, addr = l.accept()
        conn.send(new_conn)
        new_conn.close()
        l.close()

        conn.recv() 
开发者ID:IronLanguages,项目名称:ironpython3,代码行数:21,代码来源:_test_multiprocessing.py

示例11: test_rapid_restart

# 需要导入模块: import multiprocessing [as 别名]
# 或者: from multiprocessing import connection [as 别名]
def test_rapid_restart(self):
        authkey = os.urandom(32)
        manager = QueueManager(
            address=(test.support.HOST, 0), authkey=authkey, serializer=SERIALIZER)
        srvr = manager.get_server()
        addr = srvr.address
        # Close the connection.Listener socket which gets opened as a part
        # of manager.get_server(). It's not needed for the test.
        srvr.listener.close()
        manager.start()

        p = self.Process(target=self._putter, args=(manager.address, authkey))
        p.start()
        p.join()
        queue = manager.get_queue()
        self.assertEqual(queue.get(), 'hello world')
        del queue
        manager.shutdown()

        manager = QueueManager(
            address=addr, authkey=authkey, serializer=SERIALIZER)
        manager.start()
        manager.shutdown()

#
#
# 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:29,代码来源:test_multiprocessing.py

示例12: _test

# 需要导入模块: import multiprocessing [as 别名]
# 或者: from multiprocessing import connection [as 别名]
def _test(cls, address):
        conn = cls.connection.Client(address)
        conn.send('hello')
        conn.close() 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:6,代码来源:test_multiprocessing.py

示例13: test_listener_client

# 需要导入模块: import multiprocessing [as 别名]
# 或者: from multiprocessing import connection [as 别名]
def test_listener_client(self):
        for family in self.connection.families:
            l = self.connection.Listener(family=family)
            p = self.Process(target=self._test, args=(l.address,))
            p.daemon = True
            p.start()
            conn = l.accept()
            self.assertEqual(conn.recv(), 'hello')
            p.join()
            l.close() 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:12,代码来源:test_multiprocessing.py

示例14: test_deliver_challenge_auth_failure

# 需要导入模块: import multiprocessing [as 别名]
# 或者: from multiprocessing import connection [as 别名]
def test_deliver_challenge_auth_failure(self):
        class _FakeConnection(object):
            def recv_bytes(self, size):
                return b'something bogus'
            def send_bytes(self, data):
                pass
        self.assertRaises(multiprocessing.AuthenticationError,
                          multiprocessing.connection.deliver_challenge,
                          _FakeConnection(), b'abc') 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:11,代码来源:test_multiprocessing.py

示例15: _test_timeout

# 需要导入模块: import multiprocessing [as 别名]
# 或者: from multiprocessing import connection [as 别名]
def _test_timeout(cls, child, address):
        time.sleep(1)
        child.send(123)
        child.close()
        conn = multiprocessing.connection.Client(address)
        conn.send(456)
        conn.close() 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:9,代码来源:test_multiprocessing.py


注:本文中的multiprocessing.connection方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。