Skip to content
Snippets Groups Projects
Commit 12a8fba0 authored by KERDREUX Jerome's avatar KERDREUX Jerome
Browse files

Fix Event loop closed bug and format

Check the previous commit for the Evevnt loop issue. Everything should
be fine now.

Black format once again wants to change some stuffs..
parent 1b15033f
No related branches found
No related tags found
No related merge requests found
......@@ -11,6 +11,7 @@ if sys.argv[0].endswith('pkgrun'):
# this is only needed for the pkgrun command
try:
from gevent import monkey
monkey.patch_all(thread=False)
# print("Loaded gevent")
except ModuleNotFoundError:
......@@ -227,6 +228,7 @@ class ToolboxHelper(object):
# match the subscribe API (no return value)
def handle(msg: Message):
self.parse_msg(msg)
self.engine.subscribe(handle)
def parse(self):
......@@ -379,11 +381,11 @@ class ToolboxHelper(object):
def request_db_values(self, addr):
if self.db_server:
self.engine.send_request(self.device, [self.db_server, ], "get_keys_values", {'device': addr})
self.engine.send_request(self.device, [self.db_server], "get_keys_values", {'device': addr})
def request_db_devices(self, key, value):
if self.db_server:
self.engine.send_request(self.device, [self.db_server, ], "get_devices", {'key': key, 'value': value})
self.engine.send_request(self.device, [self.db_server], "get_devices", {'key': key, 'value': value})
def is_db_reply(self, msg):
if match_dev_type(msg, DB_DEV_TYPE) and msg.is_reply() and self.device.address in msg.targets:
......@@ -497,6 +499,7 @@ def dumper():
eng.subscribe(dumper_callback)
helper.run_forever()
#####################################################
# alive
#####################################################
......@@ -532,6 +535,7 @@ def is_alive():
eng.on_start(start)
helper.run_until_idle()
#####################################################
# info
#####################################################
......@@ -580,6 +584,7 @@ def info():
eng.on_start(run)
helper.run_forever()
#####################################################
# walker
#####################################################
......@@ -627,6 +632,7 @@ def walker():
eng.on_start(start)
helper.run_until_idle()
#####################################################
# log
#####################################################
......@@ -669,6 +675,7 @@ def log():
eng.subscribe(log_callback)
helper.run_forever()
#####################################################
# query db
#####################################################
......@@ -751,6 +758,7 @@ def query_db():
eng.on_start(run)
helper.run_forever()
#####################################################
# cleanup db
#####################################################
......@@ -808,6 +816,7 @@ def clean_db():
helper.run_forever()
# helper.run_until_idle()
#####################################################
# send request
#####################################################
......@@ -851,6 +860,7 @@ def send():
eng.on_start(run)
helper.run_forever()
#####################################################
# tail msg
#####################################################
......@@ -858,7 +868,9 @@ def tail():
helper = ToolboxHelper()
helper.parser.add_option("-f", dest="filter_address", help="only show given address")
helper.parser.add_option("-t", dest="filter_type", help="only show given device type")
helper.parser.add_option("-m", dest="filter_mode", help="hide some messages:\n 1=alives, 2=core actions, 3=replies, 4=all except notif")
helper.parser.add_option(
"-m", dest="filter_mode", help="hide some messages:\n 1=alives, 2=core actions, 3=replies, 4=all except notif"
)
helper.parse()
target = helper.check_address(helper.options.filter_address)
......@@ -919,6 +931,7 @@ def tail():
eng.subscribe(tail_callback)
helper.run_forever()
#####################################################
# run pkg
#####################################################
......@@ -950,6 +963,7 @@ def pkgrun():
load_pkgs()
helper.run_forever()
#####################################################
# ipdb shell on steroid
#####################################################
......@@ -969,17 +983,6 @@ def shell():
print("$ pip install ipython\n")
exit(1)
# for a unknown reason, watchdog_task raise a RuntimeError:
# "Event loop is closed" on the shell exit. To avoid issue
# we need to stop all tasks.
async def on_stop():
for task in eng.all_tasks():
logging.debug("Stopping task %s", task.get_name())
task.cancel()
await asyncio.sleep(0.1)
eng.on_stop(on_stop)
logging.getLogger("parso").setLevel(logging.WARNING)
logging.getLogger("blib2to3").setLevel(logging.WARNING)
......@@ -992,12 +995,14 @@ def shell():
from xaal.lib import Message, Attribute, Device
from xaal.monitor import Monitor
IPython.embed(banner1="============================== xAAL Shell ==============================",
IPython.embed(
banner1="============================== xAAL Shell ==============================",
banner2=f"* AsyncEngine running in background:\n* eng = {eng}\n\n",
colors="Linux",
confirm_exit=False,
separate_in='',
autoawait=True)
autoawait=True,
)
print("* Ending Engine")
eng.shutdown()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment