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


Python socket.fromshare方法代碼示例

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


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

示例1: testTypes

# 需要導入模塊: import socket [as 別名]
# 或者: from socket import fromshare [as 別名]
def testTypes(self):
        families = [socket.AF_INET, socket.AF_INET6]
        types = [socket.SOCK_STREAM, socket.SOCK_DGRAM]
        for f in families:
            for t in types:
                try:
                    source = socket.socket(f, t)
                except OSError:
                    continue # This combination is not supported
                try:
                    data = source.share(os.getpid())
                    shared = socket.fromshare(data)
                    try:
                        self.compareSockets(source, shared)
                    finally:
                        shared.close()
                finally:
                    source.close() 
開發者ID:Microvellum,項目名稱:Fluid-Designer,代碼行數:20,代碼來源:test_socket.py

示例2: testShareLocal

# 需要導入模塊: import socket [as 別名]
# 或者: from socket import fromshare [as 別名]
def testShareLocal(self):
        data = self.serv.share(os.getpid())
        s = socket.fromshare(data)
        try:
            self.compareSockets(self.serv, s)
        finally:
            s.close() 
開發者ID:Microvellum,項目名稱:Fluid-Designer,代碼行數:9,代碼來源:test_socket.py

示例3: detach

# 需要導入模塊: import socket [as 別名]
# 或者: from socket import fromshare [as 別名]
def detach(self):
            '''Get the socket.  This should only be called once.'''
            with _resource_sharer.get_connection(self._id) as conn:
                share = conn.recv_bytes()
                return socket.fromshare(share) 
開發者ID:Microvellum,項目名稱:Fluid-Designer,代碼行數:7,代碼來源:resource_sharer.py

示例4: start_worker

# 需要導入模塊: import socket [as 別名]
# 或者: from socket import fromshare [as 別名]
def start_worker(pipeout):
    parse_config()
    httpd = ThreadedTCPServer((
        State.config.get("proxy", "listen").strip(),
        State.config.getint("proxy", "port")), Proxy, bind_and_activate=False)
    mainsock = socket.fromshare(pipeout.recv())
    httpd.socket = mainsock

    print_banner()

    serve_forever(httpd) 
開發者ID:genotrance,項目名稱:px,代碼行數:13,代碼來源:px.py

示例5: run_pool

# 需要導入模塊: import socket [as 別名]
# 或者: from socket import fromshare [as 別名]
def run_pool():
    try:
        httpd = ThreadedTCPServer((State.config.get("proxy", "listen").strip(),
                                   State.config.getint("proxy", "port")), Proxy)
    except OSError as exc:
        if "attempt was made" in str(exc):
            print("Px failed to start - port in use")
        else:
            pprint(exc)
        return

    mainsock = httpd.socket

    print_banner()

    if hasattr(socket, "fromshare"):
        workers = State.config.getint("settings", "workers")
        for i in range(workers-1):
            (pipeout, pipein) = multiprocessing.Pipe()
            p = multiprocessing.Process(target=start_worker, args=(pipeout,))
            p.daemon = True
            p.start()
            while p.pid is None:
                time.sleep(1)
            pipein.send(mainsock.share(p.pid))

    serve_forever(httpd)

###
# Proxy detection 
開發者ID:genotrance,項目名稱:px,代碼行數:32,代碼來源:px.py

示例6: remoteProcessServer

# 需要導入模塊: import socket [as 別名]
# 或者: from socket import fromshare [as 別名]
def remoteProcessServer(cls, q):
        # Recreate socket from shared data
        sdata = q.get()
        message = q.get()

        s = socket.fromshare(sdata)
        s2, c = s.accept()

        # Send the message
        s2.sendall(message)
        s2.close()
        s.close() 
開發者ID:Microvellum,項目名稱:Fluid-Designer,代碼行數:14,代碼來源:test_socket.py

示例7: testShareLength

# 需要導入模塊: import socket [as 別名]
# 或者: from socket import fromshare [as 別名]
def testShareLength(self):
        data = self.serv.share(os.getpid())
        self.assertRaises(ValueError, socket.fromshare, data[:-1])
        self.assertRaises(ValueError, socket.fromshare, data+b"foo") 
開發者ID:Microvellum,項目名稱:Fluid-Designer,代碼行數:6,代碼來源:test_socket.py


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