def __init__(self, name): self.name = name self.window = NavigationManagerWindow() def update_gui(data): self.window.render() self.rerender = RerenderThread(self.window) self.rerender.render.connect(update_gui) self.rerender.start() self.window.show() # communication things self.stopped = False self.ctx = zmq.Context() self.outgoing = zhelper.zthread_fork(self.ctx, self.network_thread) self.window.outgoing = self.outgoing print("Connecting..") # wait for ready from the thread try: time.sleep(1.0) self.outgoing.recv() except zmq.error.Again: print("ERROR! Again #0") print("..CONNECTED!")
def set_name(self,new_name): self.name = new_name if self.thread_pipe: self.thread_pipe.send(exit_thread) while self.thread_pipe: sleep(.01) self.thread_pipe = zhelper.zthread_fork(self.context, self.thread_loop)
def set_name(self, new_name): self.name = new_name if self.thread_pipe: self.thread_pipe.send("EXIT_THREAD".encode('utf_8')) while self.thread_pipe: sleep(.01) self.thread_pipe = zhelper.zthread_fork(self.context, self.thread_loop)
def set_name(self, new_name): self.name = new_name if self.thread_pipe: self.thread_pipe.send(exit_thread) while self.thread_pipe: sleep(.01) self.thread_pipe = zhelper.zthread_fork(self.context, self.thread_loop)
def __init__(self, node_name, groups, message_types, ctx=None, interface=None, **kwargs): super(PyreBase, self).__init__(name=node_name, ctx=ctx) self.group_names = groups assert isinstance(message_types, list) self.message_types = message_types self.peer_directory = {} if interface: self.set_interface(interface) self.interface = interface elif 'ZSYS_INTERFACE' in os.environ: interface = os.environ['ZSYS_INTERFACE'] self.set_interface(interface) self.interface = interface self.terminated = False self.debug_msgs = kwargs.get('debug_msgs', True) self.pipe = zhelper.zthread_fork(self._ctx, self.receive_loop) assert isinstance(groups, list) for group in groups: time.sleep(ZYRE_SLEEP_TIME) self.join(group)
def __init__(self, name='unnamed Pupil', group='default group', time_grandmaster=False): super(Pupil_Sync_Node, self).__init__() self.name = name self.group = group self.group_members = {} self.menu = None self.group_menu = None self._time_grandmaster = time_grandmaster #variables for the time sync logic self.time_sync_node = None self.last_master_announce = self.get_unadjusted_time() #constants for the time sync logic self.time_sync_announce_interval = 5 self.time_sync_wait_interval_short = self.time_sync_announce_interval * 3 self.time_sync_wait_interval_long = self.time_sync_announce_interval * 4 self.context = zmq.Context() self.thread_pipe = zhelper.zthread_fork(self.context, self._thread_loop) self.timebase = 0.0 #this is the time offset
def set_name(self,new_name): self.name = new_name if self.thread_pipe: self.thread_pipe.send("EXIT_THREAD".encode('utf_8')) while self.thread_pipe: sleep(.01) self.thread_pipe = zhelper.zthread_fork(self.context, self.thread_loop)
def set_group(self,new_name): self.group = new_name if self.thread_pipe: self.thread_pipe.send(exit_thread) while self.thread_pipe: sleep(.01) self.group_members = {} self.thread_pipe = zhelper.zthread_fork(self.context, self._thread_loop)
def __init__(self, g_pool, address="tcp://*:50020"): super(Pupil_Remote, self).__init__(g_pool) self.order = .01 #excecute first self.context = g_pool.zmq_ctx self.thread_pipe = zhelper.zthread_fork(self.context, self.thread_loop) self.address = address self.start_server(address) self.menu = None
def __init__(self, g_pool,address="tcp://*:50020"): super(Pupil_Remote, self).__init__(g_pool) self.order = .01 #excecute first self.context = g_pool.zmq_ctx self.thread_pipe = zhelper.zthread_fork(self.context, self.thread_loop) self.address = address self.start_server(address) self.menu = None
def start(self): """ Starts the stream Returns: (AbstractRemoteGazePositionStream) self """ ctx = zmq.Context() self.stopped = False self.pyre_pipe = zhelper.zthread_fork(ctx, self.gaze_exchange_task) return self
def set_group(self, new_name): self.group = new_name if self.thread_pipe: self.thread_pipe.send("EXIT_THREAD".encode('utf_8')) while self.thread_pipe: sleep(.01) self.group_members = {} self.update_gui() self.thread_pipe = zhelper.zthread_fork(self.context, self.thread_loop)
def set_group(self, new_name): self.group = new_name if self.thread_pipe: self.thread_pipe.send(exit_thread) while self.thread_pipe: sleep(.01) self.group_members = {} self.update_gui() self.thread_pipe = zhelper.zthread_fork(self.context, self.thread_loop)
def set_group(self,new_name): self.group = new_name if self.thread_pipe: self.thread_pipe.send("EXIT_THREAD".encode('utf_8')) while self.thread_pipe: sleep(.01) self.group_members = {} self.update_gui() self.thread_pipe = zhelper.zthread_fork(self.context, self.thread_loop)
def __init__(self, name): self.name = name self.tele_op_active = False self.tele_op_list = [] # communication things self.stopped = False self.ctx = zmq.Context() self.outgoing = zhelper.zthread_fork(self.ctx, self.network_thread)
def start_discovery_announcements(self): self.log.debug("Start discovery announcements".format()) self.running = True self.discovery_pipe = zhelper.zthread_fork(self.ctx, self.discovery_task) d = threading.Thread(target=self._sending_announcements) d.setDaemon(True) d.start() return True
def start_discovery(self): self.log.debug("Start discovery procedure".format()) self.running = True self.controller_dl = None self.controller_ul = None self.discovery_pipe = zhelper.zthread_fork(self.ctx, self.discovery_task) while self.running: time.sleep(2)
def __init__(self, node_name="default", overlay_network_name="default"): self.ctx = zmq.Context() # define read pipe here frontend, backend = zhelper.zcreate_pipe(self.ctx) self.read_pipe = backend self.write_pipe = zhelper.zthread_fork(self.ctx, self.network_manager, \ node_name, overlay_network_name, frontend) self.node_name = node_name self.overlay_network_name = overlay_network_name
def start_discovery_announcements(self): self.log.debug("Start discovery announcements".format()) self.running = True self.discovery_pipe = zhelper.zthread_fork(self.ctx, self.discovery_task) while self.running: self.log.debug("Discovery Announcements, Downlink={}, Uplink={}".format(self.controller_dl, self.controller_ul)) msg = json.dumps({'downlink': self.controller_dl,'uplink': self.controller_ul}) self.discovery_pipe.send(msg.encode('utf_8')) time.sleep(2)
def __init__(self, g_pool, name='unnamed Pupil', group='default group'): super(Pupil_Sync, self).__init__(g_pool) self.order = .01 #excecute first self.name = name self.group = group self.group_members = {} self.menu = None self.group_menu = None self.context = zmq.Context() self.thread_pipe = zhelper.zthread_fork(self.context, self.thread_loop)
def __init__(self, g_pool,name='unnamed Pupil',group='default group'): super(Pupil_Sync, self).__init__(g_pool) self.order = .01 #excecute first self.name = name self.group = group self.group_members = {} self.menu = None self.group_menu = None self.context = zmq.Context() self.thread_pipe = zhelper.zthread_fork(self.context, self.thread_loop)
def start_server(self,new_address): if self.thread_pipe: self.stop_server() try: socket = self.context.socket(zmq.REP) socket.bind(new_address) except zmq.ZMQError as e: logger.error("Could not bind to Socket: %s. Reason: %s"%(new_address,e)) else: self.address = new_address self.thread_pipe = zhelper.zthread_fork(self.context, self.thread_loop,socket)
def __init__(self, g_pool,port="50020", host="*", use_primary_interface=True): super(Pupil_Remote, self).__init__(g_pool) self.order = .01 #excecute first self.context = g_pool.zmq_ctx self.thread_pipe = zhelper.zthread_fork(self.context, self.thread_loop) self.use_primary_interface = use_primary_interface self.host = host self.port= port self.start_server(host+':'+port) self.menu = None
def __init__(self, g_pool, port="50020", host="*", use_primary_interface=True): super().__init__(g_pool) self.order = .01 # excecute first self.context = g_pool.zmq_ctx self.thread_pipe = zhelper.zthread_fork(self.context, self.thread_loop) self.use_primary_interface = use_primary_interface self.host = host self.port = port self.start_server('tcp://{}:{}'.format(host, port)) self.menu = None
def __init__(self, g_pool, host="*", use_primary_interface=True): super().__init__(g_pool) self.order = 0.01 # excecute first self.context = g_pool.zmq_ctx self.thread_pipe = zhelper.zthread_fork(self.context, self.thread_loop) self.use_primary_interface = use_primary_interface assert type(host) == str self.host = host self.port = g_pool.preferred_remote_port self.start_server("tcp://{}:{}".format(host, self.port)) self.menu = None
def start_server(self, new_address): if self.thread_pipe: self.stop_server() try: socket = self.context.socket(zmq.REP) socket.bind(new_address) except zmq.ZMQError as e: logger.error("Could not bind to Socket: %s. Reason: %s" % (new_address, e)) else: self.address = new_address self.thread_pipe = zhelper.zthread_fork(self.context, self.thread_loop, socket)
def main(): p = ArgumentParser( description=textwrap.dedent('''\ To test, run two separate instances of chat.py on the same LAN and type into the console when they are running example usage: $ python tapio.py -h $ python tapio.py -d '''), formatter_class=RawDescriptionHelpFormatter ) p.add_argument('-d', '--debug', dest='debug', action="store_true") args = p.parse_args() # Create a StreamHandler for debugging logger = logging.getLogger("pyre") logger.setLevel(logging.INFO) if args.debug: logger.setLevel(logging.DEBUG) console = logging.StreamHandler() console.setFormatter(logging.Formatter(LOG_FORMAT)) logger.addHandler(console) logger.propagate = False ctx = zmq.Context() client = Client() chat_pipe = zhelper.zthread_fork(ctx, client.start) logger.info('starting loop') stop = False while not stop: try: if sys.version_info.major < 3: msg = raw_input('message to send: ') else: msg = input() chat_pipe.send(msg.encode('utf_8')) except (KeyboardInterrupt, SystemExit): logger.info('SIGINT Received') stop = True except AttributeError as e: stop = True logger.error(e) else: stop = True chat_pipe.send("$$STOP".encode('utf_8')) logger.info("FINISHED")
def __init__(self, g_pool, port=50020, host="*", use_primary_interface=True): super().__init__(g_pool) self.order = 0.01 # excecute first self.context = g_pool.zmq_ctx self.thread_pipe = zhelper.zthread_fork(self.context, self.thread_loop) self.use_primary_interface = use_primary_interface assert type(host) == str assert type(port) == int self.host = host self.port = g_pool.preferred_remote_port or port self.start_server("tcp://{}:{}".format(host, self.port)) self.menu = None
def __init__(self, g_pool, relay_pupil=True, relay_notifications=True): """Summary Args: relay_pupil (bool, optional): Relay pupil data relay_gaze (bool, optional): Relay gaze data relay_notifications (bool, optional): Relay notifications """ super().__init__(g_pool) self.relay_pupil = relay_pupil self.relay_notifications = relay_notifications self.context = g_pool.zmq_ctx self.thread_pipe = zhelper.zthread_fork(self.context, self.thread_loop)
def start_discovery(self): if self.running: return self.log.debug("Start discovery procedure".format()) self.running = True self.controller_dl = None self.controller_ul = None self.discovery_pipe = zhelper.zthread_fork(self.ctx, self.discovery_task) d = threading.Thread(target=self._receive_announcements) d.setDaemon(True) d.start() return True
def __init__(self, **kwargs): if not 'name' in kwargs: kwargs['name'] = 'Pupil Interface Node' super(Communicator, self).__init__(**kwargs) self.sub_addr = kwargs.get('sub_addr','tcp://127.0.0.1') self.sub_port = kwargs.get('sub_port','5000') # set callbacks to None self.network_callback = None self.subscription_callback = None self.calibration_callback = None self.recording_callback = None # used to wait for events in wait*() calls self.wait_event = Event() self.event_q = Queue() self.sub_pipe = zhelper.zthread_fork(self.context, self._sub_loop)
def __init__(self, name, CommandProto, transport="tcp"): """ Args: name: human-readable name for the actuator CommandProto: class of the the command protocol buffer expected by this actuator. """ if transport not in ("inproc", "tcp"): raise ValueError("transport must be one of {inproc, tcp}") self.name = name self.CommandProto = CommandProto context = zmq.Context.instance() self.command_pipe = zhelper.zthread_fork(context, self.run, transport=transport)
def __init__(self, g_pool, name='unnamed Pupil', group='default group'): super(Pupil_Sync, self).__init__(g_pool) self.order = .01 #excecute first self.name = name self.group = group self.group_members = {} self.menu = None self.group_menu = None self.context = zmq.Context() self.thread_pipe = zhelper.zthread_fork(self.context, self.thread_loop) #variables for the time sync logic self.sync_master = None self.sync_data = [] self.sync_to_collect = 0 self.sync_nodes = [] self.timeout = None
def __start_server(self, host: str, port: int): if self.__thread_pipe is not None: logger.warning("Pupil remote server already started") return new_address = f"{host}:{port}" self.__thread_pipe = zhelper.zthread_fork( self.g_pool.zmq_ctx, self.__thread_loop ) self.__thread_pipe.send_string("Bind", flags=zmq.SNDMORE) self.__thread_pipe.send_string(f"tcp://{new_address}") response = self.__thread_pipe.recv_string() msg = self.__thread_pipe.recv_string() if response == "Bind OK": # TODO: Do we need to verify msg == new_address? self.on_pupil_remote_server_did_start(address=new_address) return # fail logic logger.error(msg) # for service we shut down if self.g_pool.app == "service": logger.error("Port already in use.") # NOTE: We don't want a should_stop notification, but a hard termination at # this point, because Service is still initializing at this point. This way # we can prevent the eye processes from starting, where otherwise we would # have to wait for them to be started until we can close them. self.g_pool.service_should_run = False return # for capture we try to bind to a arbitrary port on the first external interface else: self.__thread_pipe.send_string("Bind", flags=zmq.SNDMORE) self.__thread_pipe.send_string("tcp://*:*") response = self.__thread_pipe.recv_string() msg = self.__thread_pipe.recv_string() if response == "Bind OK": host, port = msg.split(":") self.host = host self.port = int(port) else: logger.error(msg) raise Exception("Could not bind to port")
def __init__(self, g_pool, name='unnamed Pupil', group='default group'): super(Pupil_Sync, self).__init__(g_pool) self.order = .01 #excecute first self.name = name self.group = group self.group_members = {} self.menu = None self.group_menu = None #variables for the time sync logic self.time_sync_node = None self.last_master_announce = self.get_unadjusted_time() #constants for the time sync logic self.time_sync_announce_interval = 5 self.time_sync_wait_interval_short = self.time_sync_announce_interval * 3 self.time_sync_wait_interval_long = self.time_sync_announce_interval * 4 self.context = zmq.Context() self.thread_pipe = zhelper.zthread_fork(self.context, self.thread_loop)
def __init__(self, g_pool,name='unnamed Pupil',group='default group'): super(Pupil_Sync, self).__init__(g_pool) self.order = .01 #excecute first self.name = name self.group = group self.group_members = {} self.menu = None self.group_menu = None self.context = zmq.Context() self.thread_pipe = zhelper.zthread_fork(self.context, self.thread_loop) #variables for the time sync logic self.sync_master = None self.sync_data = [] self.sync_to_collect = 0 self.sync_nodes = [] self.timeout = None
def __init__(self, name='unnamed Pupil',group='default group',time_grandmaster=False): super(Pupil_Sync_Node, self).__init__() self.name = name self.group = group self.group_members = {} self._time_grandmaster = time_grandmaster #variables for the time sync logic self.time_sync_node = None self.last_master_announce = self.get_unadjusted_time() #constants for the time sync logic self.time_sync_announce_interval = 5 self.time_sync_wait_interval_short = self.time_sync_announce_interval * 3 self.time_sync_wait_interval_long = self.time_sync_announce_interval * 4 self.context = zmq.Context() self.thread_pipe = zhelper.zthread_fork(self.context, self._thread_loop) self.timebase = 0.0 #this is the time offset
def __init__(self, g_pool,name='unnamed Pupil',group='default group'): super(Pupil_Sync, self).__init__(g_pool) self.order = .01 #excecute first self.name = name self.group = group self.group_members = {} self.menu = None self.group_menu = None #variables for the time sync logic self.sync_node = None self.last_master_announce = self.get_monotonic_time() #constants for the time sync logic self.time_sync_announce_interval = 5 self.time_sync_wait_interval_short = self.time_sync_announce_interval * 3 self.time_sync_wait_interval_long = self.time_sync_announce_interval * 4 self.context = zmq.Context() self.thread_pipe = zhelper.zthread_fork(self.context, self.thread_loop)
except: print 'Invalid JSON string' logMessage(data) meteor['modules'].remove({'_id': str(n.uuid())}) n.stop() if __name__ == '__main__': # Create a StreamHandler for debugging logger = logging.getLogger('pyre') logger.setLevel(logging.INFO) logger.addHandler(logging.StreamHandler()) logger.propagate = False ctx = zmq.Context() database_writer = zhelper.zthread_fork(ctx, rethinkdb_writer) while True: try: msg = raw_input() database_writer.send(msg.encode('utf_8')) except (KeyboardInterrupt, SystemExit): break database_writer.send('$$STOP'.encode('utf_8')) print('FINISHED')
def __init__(self, name): self.name = name self.out_queue = Queue() # ros stuff rospy.init_node('Car2XNode', anonymous=True) self.tf = tf.TransformListener() self.nav_obstruction_pub = rospy.Publisher('/aadc/nav_obstructions', NavObstruction, queue_size=10) self.object_detection_pub = rospy.Publisher( '/aadc/object_detection/detected_objects', DetectedObjects, queue_size=10) self.marker_position_pub = rospy.Publisher( '/aadc/external_marker_position', ExternalMarkerPosition, queue_size=20) self.obstruction_pub = rospy.Publisher( '/aadc/planning/patch_occupancy', StreetPatchOccupancy, queue_size=20) self.jury_pub = rospy.Publisher('/aadc/jury/event', std_msgs.msg.String, queue_size=20) print("Waiting for tf..") self.tf.waitForTransform("world", "local", rospy.Time(), rospy.Duration(1000000.0)) self.tf.waitForTransform("local", "world", rospy.Time(), rospy.Duration(1000000.0)) print("..DONE") # communication things self.stopped = False self.ctx = zmq.Context() self.outgoing = zhelper.zthread_fork(self.ctx, self.network_thread) print("Connecting..") # wait for ready from the thread try: time.sleep(1.0) self.outgoing.recv() except zmq.error.Again: rospy.logerr("ERROR! Again #0") print("..CONNECTED!") self.event_sub = rospy.Subscriber('/aadc/planning/event', Event, self.process_event) self.marker_position_sub = rospy.Subscriber( '/aadc/marker_position', MarkerPosition, self.process_internal_marker_position) # ADD_TOPIC_PART_HERE self.object_detection_sub = rospy.Subscriber( '/aadc/object_detection/detected_objects', DetectedObjects, self.process_internal_detected_objects) self.nav_obstruction_sub = rospy.Subscriber( '/aadc/nav_obstructions', NavObstruction, self.process_internal_nav_obs)
if __name__ == '__main__': # For logging logger = logging.getLogger("pyre") logger.setLevel(logging.INFO) logger.addHandler(logging.StreamHandler()) logger.propagate = False #Create ZMQ context ctx = zmq.Context() # Ask for username NAME = input("Username: "******"--------------------------------------------------------------------------------") input_pipe.send(STOP_COMMAND.encode('utf_8'))
def start_group_communication(self): if self.thread_pipe: self.stop_group_communication() logger.debug("Starting Pupil Groups...") self.thread_pipe = zhelper.zthread_fork(self.g_pool.zmq_ctx, self._thread_loop)
if n.inbox in items and items[n.inbox] == zmq.POLLIN: n.recv() cmds += 1 if cmds == ncmds: msg = 'Got %s msgs in %0.2f sec' % (cmds, time.time() - t0) pipe.send(msg.encode('utf-8')) n.stop() if __name__ == '__main__': # Create a StreamHandler for debugging logger = logging.getLogger("pyre") logger.setLevel(logging.INFO) logger.addHandler(logging.StreamHandler()) logger.propagate = False ctx = zmq.Context() ntasks = 1000 chat_pipe = zhelper.zthread_fork(ctx, chat_task, ntasks) print("Waiting for Peer...") chat_pipe.recv() for i in range(ntasks): chat_pipe.send('hello'.encode('utf-8')) time.sleep(0.0001) print(chat_pipe.recv().decode('utf-8')) chat_pipe.send("$$STOP".encode('utf_8')) print("FINISHED")
if __name__ == '__main__': # For logging logger = logging.getLogger("pyre") logger.setLevel(logging.INFO) logger.addHandler(logging.StreamHandler()) logger.propagate = False #Create ZMQ context ctx = zmq.Context() # Ask for username NAME = input("Username: ") # Set up a background chat_task thread. We use ZeroMQ to send inter-thread messages to that thread input_pipe = zhelper.zthread_fork(ctx, chat_task) # For python 2 versions, text input of user is differently defined input = input if sys.version_info.major < 3: input = raw_input while True: try: msg = input() input_pipe.send(msg.encode( 'utf_8')) #Send the input message to the local input pipe except (KeyboardInterrupt, SystemExit): break print(
print("-----CAR COMMUNICATION STOPPED-----") n.stop() if __name__ == '__main__': # For logging logger = logging.getLogger("pyre") logger.setLevel(logging.INFO) logger.addHandler(logging.StreamHandler()) logger.propagate = False #Create ZMQ context ctx = zmq.Context() # Set up a background chat_task thread. We use ZeroMQ to send inter-thread messages to that thread local_car_pipe = zhelper.zthread_fork(ctx, chat_task) # For python 2 versions, text input of user is differently defined input = input if sys.version_info.major < 3: input = raw_input while True: try: msg = input() local_car_pipe.send(msg.encode('utf_8')) #Send the input message to the local car pipe except (KeyboardInterrupt, SystemExit): break print("--------------------------------------------------------------------------------") local_car_pipe.send(STOP_COMMAND.encode('utf_8'))
def start_group_communication(self): if self.thread_pipe: self.stop_group_communication() logger.debug('Starting Pupil Groups...') self.thread_pipe = zhelper.zthread_fork(self.g_pool.zmq_ctx, self._thread_loop)