How to use the stig.objects.aioloop.create_task function in stig

To help you get started, we’ve selected a few stig 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 rndusr / stig / stig / commands / tui / _mixin.py View on Github external
def run_func_or_coro(func_or_coro):
            if asyncio.iscoroutinefunction(func_or_coro):
                objects.aioloop.create_task(func_or_coro())
            elif asyncio.iscoroutine(func_or_coro):
                objects.aioloop.create_task(func_or_coro)
            elif func_or_coro is not None:
                func_or_coro()
github rndusr / stig / stig / commands / tui / _mixin.py View on Github external
def run_func_or_coro(func_or_coro):
            if asyncio.iscoroutinefunction(func_or_coro):
                objects.aioloop.create_task(func_or_coro())
            elif asyncio.iscoroutine(func_or_coro):
                objects.aioloop.create_task(func_or_coro)
            elif func_or_coro is not None:
                func_or_coro()
github rndusr / stig / stig / tui / tuiobjects.py View on Github external
def load_geoip_db():
    """
    Load geolocation database in a background task
    """
    def _handle_geoip_load_result(task):
        import asyncio
        try:
            task.result()
        except asyncio.CancelledError:
            pass
        except objects.geoip.GeoIPError as e:
            log.error(e)
    task = objects.aioloop.create_task(objects.geoip.load())
    task.add_done_callback(_handle_geoip_load_result)
github rndusr / stig / stig / tui / views / setting_list.py View on Github external
except ValueError as e:
            log.error('Cannot set %s = %r: %s', name, new_value, e)
        else:
            if on_success is not None:
                on_success()

    elif remote_name in objects.remotecfg:
        async def setter():
            try:
                await objects.remotecfg.set(remote_name, new_value)
            except (ValueError, objects.srvapi.ClientError) as e:
                log.error('Cannot set %s = %r: %s', name, new_value, e)
            else:
                if on_success is not None:
                    on_success()
        objects.aioloop.create_task(setter())

    else:
        raise RuntimeError('Not a setting name: %r' % name)
github rndusr / stig / stig / tui / cli.py View on Github external
if self._completer is not None:
            old_task = getattr(self, '_completion_update_task', None)
            if old_task is not None:
                old_task.cancel()

            def callback(task):
                try:
                    task.result()
                except asyncio.CancelledError:
                    pass
                else:
                    self._candsw.update_candidates()
                    self._maybe_hide_or_show_menu()

            coro = self._completer.update(self._editw.edit_text, self._editw.edit_pos)
            self._completion_update_task = aioloop.create_task(coro)
            self._completion_update_task.add_done_callback(callback)