Tell a bus to register itself on the glib main loop
765562
def glibize
      require "glib2"
      # Circumvent a ruby-glib bug
      @channels ||= []

      gio = GLib::IOChannel.new(@message_queue.socket.fileno)
      @channels << gio
      gio.add_watch(GLib::IOChannel::IN) do |_c, _ch|
        dispatch_message_queue
        true
      end
    end
267010
def run(entry_point, drivers, loop = None):
    ''' 
    '''
    program = setup(entry_point, drivers)
    dispose = program.run()
    if loop == None:
        loop = asyncio.get_event_loop()

    loop.run_forever()
    dispose()
1365864
def register(self, library: str, cbl: Callable[['_AsyncLib'], None]):
        '''
        
        '''
        self._handlers[library] = cbl
420599
def main():
    
    try:

        # Open serial port
        ser = serial.Serial('/dev/ttyUSB0', 9600)

        # Create XBee Series 1 object
        xbee = XBee(ser)


        # Send AT packet
        xbee.send('at', frame_id='A', command='DH')

        # Wait for response
        response = xbee.wait_read_frame()
        print response

        # Send AT packet
        xbee.send('at', frame_id='B', command='DL')

        # Wait for response
        response = xbee.wait_read_frame()
        print response

        # Send AT packet
        xbee.send('at', frame_id='C', command='MY')

        # Wait for response
        response = xbee.wait_read_frame()
        print response

        # Send AT packet
        xbee.send('at', frame_id='D', command='CE')

        # Wait for response
        response = xbee.wait_read_frame()
        print response
    except KeyboardInterrupt:
        pass
    finally:
        ser.close()
697557
async def system_bus_async(loop = None, **kwargs) :
    ""
    return \
        Connection \
          (
            await dbus.Connection.bus_get_async(DBUS.BUS_SYSTEM, private = False, loop = loop)
          ) \
        .register_additional_standard(**kwargs)
807879
def register(self, name):
        
        signal = Signal(providing_args=['args', 'kwargs'])
        self._registry[name] = signal
        return signal
606688
def register(nbtool):
    
    global _py_funcs
    _lazy_init()

    # Save references to the tool's load() and render() functions
    load_key = nbtool.origin + '|' + nbtool.id + '|load'
    render_key = nbtool.origin + '|' + nbtool.id + '|render'
    _py_funcs[load_key] = nbtool.load
    _py_funcs[render_key] = nbtool.render

    # Clean optional metadata for inclusion in JavaScript
    clean_description = "null" if nbtool.description is None else '"' + nbtool.description.replace('"','\\"') + '"'
    clean_version = "null" if nbtool.version is None else '"' + nbtool.version.replace('"','\\"') + '"'
    clean_tags = "null" if nbtool.tags is None else json.dumps(nbtool.tags)
    clean_attributes = "null" if nbtool.attributes is None else json.dumps(nbtool.attributes)

    # Pass the metadata to JavaScript
    IPython.display.display_javascript("""
        console.log('ok');
        NBToolManager.instance().register(new NBToolManager.NBTool({
            origin: "%s",
            id: "%s",
            name: "%s",
            description: %s,
            version: %s,
            tags: %s,
            attributes: %s,
            load: function() {
                var x = Jupyter.notebook.kernel.execute('nbtools._py_funcs["%s"]()',
                    {
                        iopub: {
                            output: function(response) {
                                // Print the return value of the Python code to the console
                                console.log(response.content.data["text/plain"]);
                            }
                        }
                    },
                    {
                        silent: false,
                        store_history: false,
                        stop_on_error: true
                    });
                return true;
            },
            render: function() {
                var x = Jupyter.notebook.kernel.execute('nbtools._py_funcs["%s"]()',
                    {
                        iopub: {
                            output: function(response) {
                                // Print the return value of the Python code to the console
                                console.log(response.content.data["text/plain"]);
                            }
                        }
                    },
                    {
                        silent: false,
                        store_history: false,
                        stop_on_error: true
                    });
                return null;
            },
        }));
    """ % (nbtool.origin, nbtool.id, nbtool.name,
           clean_description, clean_version, clean_tags, clean_attributes,
           load_key, render_key), raw=True)
    return True
1253925
def _compile_bus_injection(self):
        """"""
        string = '"""\n'
        for device, series in zip(self.devices, self.series):
            if series:
                string += 'system.' + device + '.gcall(system.dae)\n'
        string += '\n'
        string += 'system.dae.reset_small_g()\n'
        string += self.gisland
        string += '"""'
        self.bus_injection = compile(eval(string), '', 'exec')
116290
def main(self):
        
        try:
            # Start the daemon
            if not self.verify_only and not self.do_daemon_init_and_start():
                self.exit_on_error(message="Daemon initialization error", exit_code=3)

            if self.verify_only:
                self.setup_alignak_logger()

            # Load monitoring configuration files
            self.load_monitoring_config_file()

            # Set my own process title
            self.set_proctitle(self.name)

            # Now we can start our "external" modules (if any):
            self.modules_manager.start_external_instances()

            # Now we can load the retention data
            self.hook_point('load_retention')

            # And go for the main loop
            while True:
                self.do_main_loop()
                logger.info("Exited from the main loop.")

                # Exiting the main loop because of a configuration reload
                if not self.need_config_reload:
                    # If no configuration reload is required, stop the arbiter daemon
                    self.request_stop()
                else:
                    # Loop if a configuration reload is raised while
                    # still reloading the configuration
                    while self.need_config_reload:
                        # Clear the former configuration
                        self.need_config_reload = False
                        self.link_to_myself = None
                        self.conf = Config()
                        # Load monitoring configuration files
                        _ts = time.time()
                        logger.warning('--- Reloading configuration...')
                        self.load_monitoring_config_file()
                        duration = int(time.time() - _ts)
                        self.add(make_monitoring_log('info', 'CONFIGURATION RELOAD;%d' % duration))
                        logger.warning('--- Configuration reloaded, %d seconds', duration)

                        # Make a pause to let our satellites get ready...
                        pause = max(1, self.conf.daemons_new_conf_timeout)
                        if pause:
                            logger.info("Pausing %.2f seconds...", pause)
                            time.sleep(pause)

        except Exception as exp:  # pragma: no cover, this should never happen indeed ;)
            # Only a master arbiter can stop the daemons
            if self.is_master:
                # Stop the daemons
                self.daemons_stop(timeout=self.conf.daemons_stop_timeout)
            self.exit_on_exception(raised_exception=exp)
            raise
1177121
async def session_bus_async(loop = None, **kwargs) :
    ""
    return \
        Connection \
          (
            await dbus.Connection.bus_get_async(DBUS.BUS_SESSION, private = False, loop = loop)
          ) \
        .register_additional_standard(**kwargs)
1046771
def bus_get(celf, type, private, error = None) :
        ""
        error, my_error = _get_error(error)
        result = (dbus.dbus_bus_get, dbus.dbus_bus_get_private)[private](type, error._dbobj)
        my_error.raise_if_set()
        if result != None :
            result = celf(result)
        #end if
        return \
            result
617414
def write_external(self, address, value):
        """"""
        self.bus.WR_B <= 1
        self.bus.ADD <= self._x

        for _ in range(5):
            yield RisingEdge(self.clock)

        yield RisingEdge(self.clock)
        self.bus.ADD <= address + 0x4000
        self.bus.BUS_DATA <= int(value)
        yield Timer(1)  # This is hack for iverilog
        self.bus.ADD <= address + 0x4000
        self.bus.BUS_DATA <= int(value)
        yield RisingEdge(self.clock)
        self.bus.WR_B <= 0
        yield Timer(1)  # This is hack for iverilog
        self.bus.BUS_DATA <= int(value)
        self.bus.WR_B <= 0
        yield RisingEdge(self.clock)
        self.bus.WR_B <= 0
        yield Timer(1)  # This is hack for iverilog
        self.bus.BUS_DATA <= int(value)
        self.bus.WR_B <= 0
        yield RisingEdge(self.clock)
        self.bus.WR_B <= 1
        self.bus.BUS_DATA <= self._high_impedence
        yield Timer(1)  # This is hack for iverilog
        self.bus.WR_B <= 1
        self.bus.BUS_DATA <= self._high_impedence
        yield RisingEdge(self.clock)
        self.bus.WR_B <= 1
        self.bus.ADD <= self._x

        for _ in range(5):
            yield RisingEdge(self.clock)
388059
def gcall(func, *args, **kwargs):
    
    def idle():
        with gdk.lock:
            return bool(func(*args, **kwargs))
    return gobject.idle_add(idle)
1367930
def session_bus(**kwargs) :
    ""
    return \
        Connection(dbus.Connection.bus_get(DBUS.BUS_SESSION, private = False)) \
        .register_additional_standard(**kwargs)
632099
def system_bus(**kwargs) :
    ""
    return \
        Connection(dbus.Connection.bus_get(DBUS.BUS_SYSTEM, private = False)) \
        .register_additional_standard(**kwargs)
89262
def runctx(self, cmd, globals, locals):
        """"""
        with self():
            exec(cmd, globals, locals)
        return self
270522
def createDbusProxyObject(bus_name, object_path, bus=None):
    '''
    
    '''
    bus = bus or dbus.SessionBus.get_session()
    return bus.get_object(bus_name, object_path)