本文整理汇总了Python中multiprocessing.connection.Listener.recv方法的典型用法代码示例。如果您正苦于以下问题:Python Listener.recv方法的具体用法?Python Listener.recv怎么用?Python Listener.recv使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类multiprocessing.connection.Listener
的用法示例。
在下文中一共展示了Listener.recv方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: ProcListener
# 需要导入模块: from multiprocessing.connection import Listener [as 别名]
# 或者: from multiprocessing.connection.Listener import recv [as 别名]
class ProcListener(threading.Thread):
def __init__(self, addr, authkey):
threading.Thread.__init__(self)
self.running = False
self.connections = []
self.bus = None
self.addr = addr
self.authkey = authkey
self.listener = Listener(addr, authkey=authkey)
self.setDaemon(True)
def run(self):
self.bus.log("Listening for incoming connections")
self.running = True
while self.running:
conn = self.listener.accept()
self.connections.append(conn)
def stop(self):
if not self.running:
return
self.bus.log("Stopping listener")
self.running = False
for conn in self.connections:
if conn:
conn.close()
# if the listener is blocked in the accept() call
# it will lock the thread, so by connecting to it
# we unblock it
c = Client(self.addr, authkey=self.authkey)
c.close()
self.connections = []
self.listener.close()
def recv(self):
return self.listener.recv()
示例2: Listener
# 需要导入模块: from multiprocessing.connection import Listener [as 别名]
# 或者: from multiprocessing.connection.Listener import recv [as 别名]
import time
import multiprocessing as mp
from multiprocessing.connection import Listener
address = ('localhost',6111)
listener = Listener(address)
while True:
print 'Listening...'
if listener.poll():
cmd = listener.recv()
print 'recieved: ', cmd
time.sleep(5)