def reply_handler(future): reply = future.result() reqnr = future.reqnr echo, id = reply if echo.lower() == 'stop': yoton.stop_event_loop() else: self.assertEqual(echo[:3], 'msg') contextnr = { self._context1.id:1, self._context2.id:2, self._context3.id:3}[long(id,16)] print('request %s from %i handled by context %i.' % (echo, reqnr, contextnr))
def reply_handler(future): reply = future.result() reqnr = future.reqnr echo, id = reply if echo.lower() == "stop": yoton.stop_event_loop() else: self.assertEqual(echo[:3], "msg") contextnr = { self._context1.id: 1, self._context2.id: 2, self._context3.id: 3, }[long(id, 16)] print("request %s from %i handled by context %i." % (echo, reqnr, contextnr))
def reply_handler(future): # Check error, cancelled, or get number if future.exception(): # Calling result() would raise the exception, so lets just # print it and make up our own number print('oops: ' + str(future.exception())) number = 1 elif future.cancelled(): print('oops: request was cancelled.') else: number = future.result() if number > 0: print('we now have %i.' % number) time.sleep(0.5) new_future = req.reduce(number) new_future.add_done_callback(reply_handler) else: print('Done') yoton.stop_event_loop()
def on_new_state(channel): state = channel.recv() print("%i received state %s" % (id(channel), state)) if state == "stop": yoton.stop_event_loop()
def message_handler(): message = sub.recv(False) if message: print(message) if message.lower() == 'stop': yoton.stop_event_loop()
def on_new_state(channel): state = channel.recv() print('%i received state %s' % (id(channel), state)) if state == 'stop': yoton.stop_event_loop()