本文整理汇总了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")