How to use the qi.async function in qi

To help you get started, we’ve selected a few qi examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github pepperhacking / studiotoolkit / python / stk / runner.py View on Github external
activity.logger.error(msg)
                        else:
                            print msg
                    finally:
                        qiapp.stop()
            qi.async(activity.on_start).addCallback(handle_on_start_done)

        # Run the QiApplication, which runs until someone calls qiapp.stop()
        qiapp.run()

    finally:
        # Cleanup
        if hasattr(activity, "on_stop"):
            # We need a qi.async call so that if the class is single threaded,
            # it will wait for callbacks to be finished.
            qi.async(activity.on_stop).wait()
        if service_id:
            qiapp.session.unregisterService(service_id)
github pepperhacking / studiotoolkit / python / stk / runner.py View on Github external
service_id = qiapp.session.registerService(service_name, activity)

        if hasattr(activity, "on_start"):
            def handle_on_start_done(on_start_future):
                "Custom callback, for checking errors"
                if on_start_future.hasError():
                    try:
                        msg = "Error in on_start(), stopping application: %s" \
                            % on_start_future.error()
                        if hasattr(activity, "logger"):
                            activity.logger.error(msg)
                        else:
                            print msg
                    finally:
                        qiapp.stop()
            qi.async(activity.on_start).addCallback(handle_on_start_done)

        # Run the QiApplication, which runs until someone calls qiapp.stop()
        qiapp.run()

    finally:
        # Cleanup
        if hasattr(activity, "on_stop"):
            # We need a qi.async call so that if the class is single threaded,
            # it will wait for callbacks to be finished.
            qi.async(activity.on_stop).wait()
        if service_id:
            qiapp.session.unregisterService(service_id)
github aldebaran / naoqi_navigation_samples / places / explorationManager.py View on Github external
    @qi.bind()
    def disconnectSubscribers(self):
        """ disconnect all subscribers from callbacks """
        qi.info(self.serviceName, "DISCONNECTING SUBSCRIBERS")
        if self.subscribeToggle:
            for event in self.subscribers.keys():
                future = qi.async(self.disconnectSubscriber, event, delay = 0)
                future.wait(1000) # add a timeout to avoid deadlock
                if not future.isFinished():
                    qi.error(self.serviceName, "disconnectSubscribers", "Failed disconnecting %s subscribers" % event)
            self.subscribeToggle = False
github pepperhacking / studiotoolkit / python / stk / coroutines.py View on Github external
def __init__(self, time_in_secs):
        FutureWrapper.__init__(self)
        time_in_microseconds = int(MICROSECONDS_PER_SECOND * time_in_secs)
        self.fut = qi.async(self.set_finished, delay=time_in_microseconds)