Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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()
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()
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)
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)
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)