當前位置: 首頁>>代碼示例>>Python>>正文


Python socket.socketpair方法代碼示例

本文整理匯總了Python中socket.socketpair方法的典型用法代碼示例。如果您正苦於以下問題:Python socket.socketpair方法的具體用法?Python socket.socketpair怎麽用?Python socket.socketpair使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在socket的用法示例。


在下文中一共展示了socket.socketpair方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: __init__

# 需要導入模塊: import socket [as 別名]
# 或者: from socket import socketpair [as 別名]
def __init__(self, app, QAbstractSocket):
        self._app = app
        self.old_fd = None
        # Create a socket pair
        self.wsock, self.rsock = socketpair(type=SOCK_DGRAM)
        self.socket = QAbstractSocket(QAbstractSocket.UdpSocket, app)
        # Let Qt listen on the one end
        self.socket.setSocketDescriptor(self.rsock.fileno())
        # And let Python write on the other end
        self.wsock.setblocking(False)
        self.old_fd = signal.set_wakeup_fd(self.wsock.fileno())
        # First Python code executed gets any exception from
        # the signal handler, so add a dummy handler first
        self.socket.readyRead.connect(lambda : None)
        # Second handler does the real handling
        self.socket.readyRead.connect(self._readSignal) 
開發者ID:mherrmann,項目名稱:fbs,代碼行數:18,代碼來源:_signal.py

示例2: test_read_while_writeable

# 需要導入模塊: import socket [as 別名]
# 或者: from socket import socketpair [as 別名]
def test_read_while_writeable(self):
        # Ensure that write events don't come in while we're waiting for
        # a read and haven't asked for writeability. (the reverse is
        # difficult to test for)
        client, server = socket.socketpair()
        try:
            def handler(fd, events):
                self.assertEqual(events, IOLoop.READ)
                self.stop()
            self.io_loop.add_handler(client.fileno(), handler, IOLoop.READ)
            self.io_loop.add_timeout(self.io_loop.time() + 0.01,
                                     functools.partial(server.send, b'asdf'))
            self.wait()
            self.io_loop.remove_handler(client.fileno())
        finally:
            client.close()
            server.close() 
開發者ID:tao12345666333,項目名稱:tornado-zh,代碼行數:19,代碼來源:ioloop_test.py

示例3: testDaemonConnectedSocket

# 需要導入模塊: import socket [as 別名]
# 或者: from socket import socketpair [as 別名]
def testDaemonConnectedSocket(self):
        try:
            Pyro5.config.SERVERTYPE = "thread"
            with Pyro5.server.Daemon() as d:
                assert "Thread" in d.transportServer.__class__.__name__
            s1, s2 = socket.socketpair()
            with Pyro5.server.Daemon(connected_socket=s1) as d:
                assert d.locationStr=="./u:<<not-bound>>" or d.locationStr.startswith("127.0.")
                assert not("Thread" in d.transportServer.__class__.__name__)
                assert "Existing" in d.transportServer.__class__.__name__
            Pyro5.config.SERVERTYPE = "multiplex"
            with Pyro5.server.Daemon() as d:
                assert "Multiplex" in d.transportServer.__class__.__name__
            s1, s2 = socket.socketpair()
            with Pyro5.server.Daemon(connected_socket=s1) as d:
                assert d.locationStr=="./u:<<not-bound>>" or d.locationStr.startswith("127.0.")
                assert not("Multiplex" in d.transportServer.__class__.__name__)
                assert "Existing" in d.transportServer.__class__.__name__
        finally:
            Pyro5.config.SERVERTYPE = "thread" 
開發者ID:irmen,項目名稱:Pyro5,代碼行數:22,代碼來源:test_daemon.py

示例4: test_issue30058

# 需要導入模塊: import socket [as 別名]
# 或者: from socket import socketpair [as 別名]
def test_issue30058(self):
        # changelist must be an iterable
        kq = select.kqueue()
        a, b = socket.socketpair()
        ev = select.kevent(a, select.KQ_FILTER_READ, select.KQ_EV_ADD | select.KQ_EV_ENABLE)

        kq.control([ev], 0)
        # not a list
        kq.control((ev,), 0)
        # __len__ is not consistent with __iter__
        class BadList:
            def __len__(self):
                return 0
            def __iter__(self):
                for i in range(100):
                    yield ev
        kq.control(BadList(), 0)
        # doesn't have __len__
        kq.control(iter([ev]), 0)

        a.close()
        b.close()
        kq.close() 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:25,代碼來源:test_kqueue.py

示例5: Pipe

# 需要導入模塊: import socket [as 別名]
# 或者: from socket import socketpair [as 別名]
def Pipe(duplex=True):
        '''
        Returns pair of connection objects at either end of a pipe
        '''
        if duplex:
            s1, s2 = socket.socketpair()
            s1.setblocking(True)
            s2.setblocking(True)
            c1 = _multiprocessing.Connection(os.dup(s1.fileno()))
            c2 = _multiprocessing.Connection(os.dup(s2.fileno()))
            s1.close()
            s2.close()
        else:
            fd1, fd2 = os.pipe()
            c1 = _multiprocessing.Connection(fd1, writable=False)
            c2 = _multiprocessing.Connection(fd2, readable=False)

        return c1, c2 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:20,代碼來源:connection.py

示例6: __init__

# 需要導入模塊: import socket [as 別名]
# 或者: from socket import socketpair [as 別名]
def __init__(self,
                 processor,
                 lsocket,
                 inputProtocolFactory=None,
                 outputProtocolFactory=None,
                 threads=10):
        self.processor = processor
        self.socket = lsocket
        self.in_protocol = inputProtocolFactory or TBinaryProtocolFactory()
        self.out_protocol = outputProtocolFactory or self.in_protocol
        self.threads = int(threads)
        self.clients = {}
        self.tasks = Queue.Queue()
        self._read, self._write = socket.socketpair()
        self.prepared = False
        self._stop = False 
開發者ID:XiaoMi,項目名稱:galaxy-sdk-python,代碼行數:18,代碼來源:TNonblockingServer.py

示例7: test_read_while_writeable

# 需要導入模塊: import socket [as 別名]
# 或者: from socket import socketpair [as 別名]
def test_read_while_writeable(self):
        # Ensure that write events don't come in while we're waiting for
        # a read and haven't asked for writeability. (the reverse is
        # difficult to test for)
        client, server = socket.socketpair()
        try:

            def handler(fd, events):
                self.assertEqual(events, IOLoop.READ)
                self.stop()

            self.io_loop.add_handler(client.fileno(), handler, IOLoop.READ)
            self.io_loop.add_timeout(
                self.io_loop.time() + 0.01, functools.partial(server.send, b"asdf")
            )
            self.wait()
            self.io_loop.remove_handler(client.fileno())
        finally:
            client.close()
            server.close() 
開發者ID:opendevops-cn,項目名稱:opendevops,代碼行數:22,代碼來源:ioloop_test.py

示例8: socketpair

# 需要導入模塊: import socket [as 別名]
# 或者: from socket import socketpair [as 別名]
def socketpair(family=socket.AF_INET, type=socket.SOCK_STREAM, proto=0):
        with contextlib.closing(socket.socket(family, type, proto)) as l:
            l.bind(("localhost", 0))
            l.listen()
            c = socket.socket(family, type, proto)
            try:
                c.connect(l.getsockname())
                caddr = c.getsockname()
                while True:
                    a, addr = l.accept()
                    # check that we've got the correct client
                    if addr == caddr:
                        return c, a
                    a.close()
            except OSError:
                c.close()
                raise


# TODO: write more tests. 
開發者ID:aliyun,項目名稱:oss-ftp,代碼行數:22,代碼來源:test_ioloop.py

示例9: test__copy_eof_on_all

# 需要導入模塊: import socket [as 別名]
# 或者: from socket import socketpair [as 別名]
def test__copy_eof_on_all(self):
        """Test the empty read EOF case on both master_fd and stdin."""
        read_from_stdout_fd, mock_stdout_fd = self._pipe()
        pty.STDOUT_FILENO = mock_stdout_fd
        mock_stdin_fd, write_to_stdin_fd = self._pipe()
        pty.STDIN_FILENO = mock_stdin_fd
        socketpair = socket.socketpair()
        masters = [s.fileno() for s in socketpair]
        self.fds.extend(masters)

        os.close(masters[1])
        socketpair[1].close()
        os.close(write_to_stdin_fd)

        # Expect two select calls, the last one will cause IndexError
        pty.select = self._mock_select
        self.select_rfds_lengths.append(2)
        self.select_rfds_results.append([mock_stdin_fd, masters[0]])
        # We expect that both fds were removed from the fds list as they
        # both encountered an EOF before the second select call.
        self.select_rfds_lengths.append(0)

        with self.assertRaises(IndexError):
            pty._copy(masters[0]) 
開發者ID:aliyun,項目名稱:oss-ftp,代碼行數:26,代碼來源:test_pty.py

示例10: __init__

# 需要導入模塊: import socket [as 別名]
# 或者: from socket import socketpair [as 別名]
def __init__(self,
                 processor,
                 lsocket,
                 inputProtocolFactory=None,
                 outputProtocolFactory=None,
                 threads=10):
        self.processor = processor
        self.socket = lsocket
        self.in_protocol = inputProtocolFactory or TBinaryProtocolFactory()
        self.out_protocol = outputProtocolFactory or self.in_protocol
        self.threads = int(threads)
        self.clients = {}
        self.tasks = queue.Queue()
        self._read, self._write = socket.socketpair()
        self.prepared = False
        self._stop = False 
開發者ID:Aditmadzs,項目名稱:Protect4,代碼行數:18,代碼來源:TNonblockingServer.py

示例11: test_client_destroy_listener

# 需要導入模塊: import socket [as 別名]
# 或者: from socket import socketpair [as 別名]
def test_client_destroy_listener():
    global a, b
    s1, s2 = socket.socketpair(socket.AF_UNIX, socket.SOCK_STREAM, 0)
    a = 0
    b = 0

    display = Display()
    client = Client(display, s1.fileno())

    destroy_listener_a = Listener(destroy_notify_a)
    destroy_listener_b = Listener(destroy_notify_b)

    client.add_destroy_listener(destroy_listener_a)
    client.add_destroy_listener(destroy_listener_b)

    destroy_listener_a.remove()

    client.destroy()

    assert a == 0
    assert b == 1 
開發者ID:flacjacket,項目名稱:pywayland,代碼行數:23,代碼來源:test_client_destroy.py

示例12: test_create_resource

# 需要導入模塊: import socket [as 別名]
# 或者: from socket import socketpair [as 別名]
def test_create_resource():
    s1, s2 = socket.socketpair(socket.AF_UNIX, socket.SOCK_STREAM, 0)
    display = Display()
    client = Client(display, s1.fileno())

    # Create resource
    res = WlDisplay.resource_class(client, version=4)

    assert res.version == 4

    # Fetching the client object by id gives the resource back again
    assert client.get_object(res.id) == res

    client.user_data = 0xbee
    assert client.user_data == 0xbee

    client.destroy()
    display.destroy()

    s2.close() 
開發者ID:flacjacket,項目名稱:pywayland,代碼行數:22,代碼來源:test_resource.py

示例13: notest_create_resource_with_same_id

# 需要導入模塊: import socket [as 別名]
# 或者: from socket import socketpair [as 別名]
def notest_create_resource_with_same_id():
    s1, s2 = socket.socketpair(socket.AF_UNIX, socket.SOCK_STREAM, 0)
    display = Display()
    client = Client(display, s1.fileno())

    # Create resource
    res = WlDisplay.resource_class(client, version=2)
    assert client.get_object(res.id) == res

    # This should replace the old one
    res2 = WlDisplay.resource_class(client, version=1, id=res.id)
    assert client.get_object(res.id) == res2

    res2.destroy()
    res.destroy()

    client.destroy()
    display.destroy()

    s2.close() 
開發者ID:flacjacket,項目名稱:pywayland,代碼行數:22,代碼來源:test_resource.py

示例14: _start

# 需要導入模塊: import socket [as 別名]
# 或者: from socket import socketpair [as 別名]
def _start(self, args, shell, stdin, stdout, stderr, bufsize, **kwargs):
        stdin_w = None
        if stdin == subprocess.PIPE:
            # Use a socket pair for stdin, since not all platforms
            # support selecting read events on the write end of a
            # socket (which we use in order to detect closing of the
            # other end).  Notably this is needed on AIX, and works
            # just fine on other platforms.
            stdin, stdin_w = self._loop._socketpair()

            # Mark the write end of the stdin pipe as non-inheritable,
            # needed by close_fds=False on Python 3.3 and older
            # (Python 3.4 implements the PEP 446, socketpair returns
            # non-inheritable sockets)
            _set_inheritable(stdin_w.fileno(), False)
        self._proc = subprocess.Popen(
            args, shell=shell, stdin=stdin, stdout=stdout, stderr=stderr,
            universal_newlines=False, bufsize=bufsize, **kwargs)
        if stdin_w is not None:
            stdin.close()
            self._proc.stdin = open(stdin_w.detach(), 'wb', buffering=bufsize) 
開發者ID:Microvellum,項目名稱:Fluid-Designer,代碼行數:23,代碼來源:unix_events.py

示例15: test__copy_eof_on_all

# 需要導入模塊: import socket [as 別名]
# 或者: from socket import socketpair [as 別名]
def test__copy_eof_on_all(self):
        """Test the empty read EOF case on both master_fd and stdin."""
        read_from_stdout_fd, mock_stdout_fd = self._pipe()
        pty.STDOUT_FILENO = mock_stdout_fd
        mock_stdin_fd, write_to_stdin_fd = self._pipe()
        pty.STDIN_FILENO = mock_stdin_fd
        socketpair = self._socketpair()
        masters = [s.fileno() for s in socketpair]

        os.close(masters[1])
        socketpair[1].close()
        os.close(write_to_stdin_fd)

        # Expect two select calls, the last one will cause IndexError
        pty.select = self._mock_select
        self.select_rfds_lengths.append(2)
        self.select_rfds_results.append([mock_stdin_fd, masters[0]])
        # We expect that both fds were removed from the fds list as they
        # both encountered an EOF before the second select call.
        self.select_rfds_lengths.append(0)

        with self.assertRaises(IndexError):
            pty._copy(masters[0]) 
開發者ID:Microvellum,項目名稱:Fluid-Designer,代碼行數:25,代碼來源:test_pty.py


注:本文中的socket.socketpair方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。