本文整理匯總了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()
示例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()
示例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)
示例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)
示例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
示例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()
示例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")