Skip to content
This repository has been archived by the owner on Apr 22, 2024. It is now read-only.

Fix Runtime errors when closing Kytos #1238

Merged
merged 8 commits into from
May 31, 2021
Merged

Fix Runtime errors when closing Kytos #1238

merged 8 commits into from
May 31, 2021

Conversation

rmotitsuki
Copy link
Member

Fix issue #1235

📑 Description of the Change

Fixed kytosd shutdown to cancel tasks before closing the event loop that executes the tasks.
Closing the event loop while tasks are being completed causes Future Runtime errors.

💻 Verification Process

Verified using the command pkill kytosd with kytos in daemon and foreground modes.

@hdiogenes
Copy link
Member

@rmotitsuki the asyncio API has changed in Python 3.9. I tried to make the code compatible with the new versions (as per this Jupyter example), but I'm receiving this error now:

2021-04-30 12:45:18,950 - INFO [kytos.core.controller] (MainThread) Shutting down NApp kytos/of_core...
2021-04-30 12:45:18,961 - INFO [kytos.core.api_server] (MainThread) The Rest endpoints from /api/kytos/of_core/ were disabled.
---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
~/src/kytos/kytos/bin/kytosd in <module>
      5 __file__ = '/Users/humberto/src/kytos/kytos/bin/kytosd'
      6 with open(__file__) as f:
----> 7     exec(compile(f.read(), __file__, 'exec'))

~/src/kytos/kytos/bin/kytosd in <module>
      4 from kytos.core import kytosd
      5
----> 6 kytosd.main()

~/src/kytos/kytos/kytos/core/kytosd.py in main()
    105
    106     if config.foreground or not config.daemon:
--> 107         async_main(config)
    108     else:
    109         with daemon.DaemonContext():

~/src/kytos/kytos/kytos/core/kytosd.py in async_main(config)
    168         controller.log.info("Shutting down Kytos...")
    169     finally:
--> 170         pending = [t for t in asyncio_all_tasks() if
    171                    t is not asyncio_current_task()]
    172         for task in pending:

/usr/local/Cellar/python@3.9/3.9.4/Frameworks/Python.framework/Versions/3.9/lib/python3.9/asyncio/tasks.py in all_tasks(loop)
     42     """Return a set of all tasks for the loop."""
     43     if loop is None:
---> 44         loop = events.get_running_loop()
     45     # Looping over a WeakSet (_all_tasks) isn't safe as it can be updated from another
     46     # thread while we do so. Therefore we cast it to list prior to filtering. The list

RuntimeError: no running event loop

@hdiogenes hdiogenes merged commit 591d9b0 into kytos:master May 31, 2021
@hdiogenes hdiogenes added this to the 2021.final milestone May 31, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants