本文整理匯總了Python中receiver.Receiver.join方法的典型用法代碼示例。如果您正苦於以下問題:Python Receiver.join方法的具體用法?Python Receiver.join怎麽用?Python Receiver.join使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類receiver.Receiver
的用法示例。
在下文中一共展示了Receiver.join方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: emulate
# 需要導入模塊: from receiver import Receiver [as 別名]
# 或者: from receiver.Receiver import join [as 別名]
def emulate(args):
'''
Starts the Sender/Receiver process threads, sleeps for
args.RUNTIME, and terminates both threads. Returns a tuple of
lists: (s_log, r_log), where s_log is sender's log and r_log is
receiver's log.
'''
args.SENDER_TIMEOUT = float(args.SENDER_TIMEOUT)
args.RUNTIME = float(args.RUNTIME)
assert args.SENDER_TIMEOUT > 0
assert args.RUNTIME > 0
s = Sender(args.SENDER_TIMEOUT)
r = Receiver()
s.set_remote_endpoint(r)
r.set_remote_endpoint(s)
r.daemon = True
s.daemon = True
# Start the sender process.
s.start()
r.start()
try:
time.sleep(args.RUNTIME)
except KeyboardInterrupt:
print "Interrupted, terminating."
# We have to be careful with terminating the two threads, as they
# can only exit in specific states, and we can cause a deadlock.
# First, we terminate the sender, and wait for it to finish. Once
# this happens, we know that the receiver is in an ok terminal
# state, so we terminate it right after.
s.terminate()
s.join()
r.terminate()
r.join()
#s.log.append((([0,0], "S-TERM")))
#r.log.append((([0,0], "R-TERM")))
# At this point, the sender is not generating any more
# messages. But, we might have some oustanding messages in
# receiver's queue. So, process these, if any:
while not r.rx_queue.empty():
# Receive msg and generate any outstanding acks.
r.transition()
r.transition()
r.transition()
# Consume any outstanding acks on the sender's side.
s.consume_acks()
return (s.log, r.log)
示例2: ncd_loop
# 需要導入模塊: from receiver import Receiver [as 別名]
# 或者: from receiver.Receiver import join [as 別名]
def ncd_loop(doInit, dlThreadNum):
ndutil.setTimezone()
#read config
cnfManager = CnfManager()
cnfManager.load('./ndc.cnf')
cnfData = cnfManager.getCnfData()
#check dirs
ndutil.enableDir(cnfData['dirWorking'])
ndutil.enableDir(cnfData['dirStore'])
#ndlcom
logger = Logger('nDroid-Crawler', cnfData['ndlComHost'], cnfData['ndlComPort'])
logger.logger('Initiating')
dbManager = DbManager(cnfData['dbHost'], cnfData['dbUser'], cnfData['dbPass'], cnfData['dbName'])
if doInit:
dbManager.create_table()
os.system('rm -f %s/*' % cnfData['dirWorking'])
os.system('rm -f %s/*' % cnfData['dirStore'])
#logger.logger('Customizing Spiders')
#spiderGenerator = SpiderGenerator('template', 'spider/spiders')
#for spider in cnfData['spiders']:
# spiderGenerator.gen_spider(spider, cnfData[spider]['startPage'], cnfData[spider]['stopPage'])
rpQueue = Queue()
pdQueue = Queue()
dpQueue = Queue()
pdLock = threading.Lock()
rpcMonitor = RpcMonitor(logger, cnfData['rpcPort'], cnfData['rpcAuth'], 'RpcMonitor')
rpcMonitor.setGlobalInfo(ndutil.getCurrentTimeStr(), 'Standalone', dlThreadNum)
rpcMonitor.setDownloadTotal(pdQueue.qsize())
rpcMonitor.setPdQueueSize(pdQueue.qsize())
botScheduler = BotScheduler(logger, rpcMonitor, cnfData['spiders'], cnfData['spiderCnfs'], 'BotScheduler')
receiver = Receiver(logger, rpcMonitor, rpQueue, cnfData['receiverPort'], 'Receiver')
preProcessor = PreProcessor(logger, rpcMonitor, rpQueue, pdQueue, pdLock, dbManager, 'PreProcessor')
downloader = Downloader([logger, rpcMonitor, pdQueue, dpQueue, pdLock, dlThreadNum, cnfData['dirWorking']], 'Downloader')
processor = Processor(logger, rpcMonitor, dpQueue, pdLock, pdQueue, dbManager, cnfData['dirWorking'], cnfData['dirStore'], 'Processor')
logger.logger('Starting Threads')
rpcMonitor.start()
botScheduler.start()
receiver.start()
preProcessor.start()
downloader.start()
processor.start()
processor.join()
downloader.join()
preProcessor.join()
receiver.join()
botScheduler.join()
rpcMonitor.join()
示例3: __init__
# 需要導入模塊: from receiver import Receiver [as 別名]
# 或者: from receiver.Receiver import join [as 別名]
class Main:
def __init__(self, UPLOAD=True, USE_GUI=True, USE_FILESTREAM=False):
self._socket_address = 'src/client/data_stream.sock'
self._receiver = Receiver(self._socket_address)
self._geo_listen = Geometry()
self._frequency = 15
if USE_FILESTREAM:
self._stream = FileStream(
"gen_data/downtown-east2_only_turn_sigs_speed_lims.json",
self._socket_address)
self._send_frequency = 1
self._speed_limit = None
self._speed_time = None
self._gui = None
self._forgot_signals_event = threading.Event()
self._speeding_event = threading.Event()
self._aggressive_event = threading.Event()
self._green_event = threading.Event()
self._green_event.direction = None
self._speeding_event.speed_limit = None
self._last_turn_forget = None
self._turn_analyzer = TurnSignalAnalyzer(self._forgot_signals_event)
self._speeding_analyzer = SpeedingAnalyzer(self._speeding_event)
self._green = Green(1, self._green_event)
self._aggressive_analyze = AggressiveAnalyzer(self._aggressive_event)
self._evaluatebox_last_time = None
if USE_GUI:
self._gui = GUI(self._receiver.is_alive)
t = threading.Thread(target=self._mainloop, daemon=True)
t.daemon = True
t.start()
if UPLOAD:
self._distributor = Distributor(
'/src/client/upload_stream.sock', self._send_frequency)
s = threading.Thread(target=self._sender, daemon=True)
s.start()
if USE_GUI:
self._gui.mainloop()
else:
self._receiver.join() # keep main from exiting
def _mainloop(self):
while True:
sleep(1 / self._frequency)
if self._evaluatebox_last_time is None or self._evaluatebox_last_time - time.time() > 5:
self._evaluatebox_last_time = time.time()
self._gui._evaluate_box.set_value(EvaluateBox.GOOD)
if self._gui is None:
continue
if Geometry._pos is not None:
if Geometry._inter_pos:
self._gui.set_coords(*Geometry._inter_pos)
else:
self._gui.set_coords(*Geometry._pos)
if Geometry._marker is not None:
self._gui.set_marker(Geometry._marker)
if self._forgot_signals_event.is_set():
self._last_turn_forget = time.time()
self._gui._turn_signal_sym.set_vibrate(10)
self._forgot_signals_event.clear()
if self._last_turn_forget is not None and time.time() - self._last_turn_forget > 3:
self._gui._turn_signal_sym.set_vibrate(0)
if self._evaluatebox_last_time is None or time.time() - \
self._evaluatebox_last_time > 3:
if self._aggressive_event.is_set():
self._gui._evaluate_box.set_value(EvaluateBox.BAD)
self._evaluatebox_last_time = time.time()
self._aggressive_event.clear()
elif self._green_event.is_set():
if self._green_event.direction == 'up':
self._gui._evaluate_box.set_value(EvaluateBox.GEAR_UP)
elif self._green_event.direction == 'down':
self._gui._evaluate_box.set_value(
EvaluateBox.GEAR_DOWN)
self._evaluatebox_last_time = time.time()
self._green_event.clear()
else:
self._gui._evaluate_box.set_value(EvaluateBox.GOOD)
if self._speed_limit != self._speeding_event.speed_limit:
self._speed_limit = self._speeding_event.speed_limit
self._gui.set_speed_limit(self._speed_limit)
if self._speeding_event.is_set():
offset = 3
self._gui._speed_limit_sym.set_vibrate(
offset + (10 - offset) * self._speeding_event.speeding_percentage)
self._speeding_event.clear()
self._speed_time = time.time()
elif self._speed_time is not None and time.time() - self._speed_time > 2:
#.........這裏部分代碼省略.........