Skip to content

Commit

Permalink
pass IOLoop to ASGI middleware
Browse files Browse the repository at this point in the history
  • Loading branch information
michalslomczynski committed Dec 19, 2023
1 parent 6d1f904 commit 4bc77b3
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions vmaas/reposcan/reposcan.py
Original file line number Diff line number Diff line change
Expand Up @@ -842,14 +842,15 @@ class SyncTask:
_running_task_type = None
_pid = None
workers = Pool(1)
ioloop = IOLoop.current()

@classmethod
def start(cls, task_type, func, callback, *args, **kwargs):
"""Start specified function with given parameters in separate worker."""
cls._running = True
cls._running_task_type = task_type
cls._pid = cls.workers._pool[0].pid # pylint: disable=protected-access
ioloop = IOLoop.instance()
ioloop = IOLoop.current()

def _callback(result):
ioloop.add_callback(lambda: callback(result))
Expand Down Expand Up @@ -953,4 +954,4 @@ def set_headers(response): # pylint: disable=unused-variable
response.headers["Access-Control-Allow-Headers"] = "Content-Type"
return response

return ASGIMiddleware(app) # As of connexion >3.0 ASGI server should be used as default, otherwise wrapped by such middleware.
return ASGIMiddleware(app, loop=SyncTask.ioloop) # As of connexion >3.0 ASGI server should be used as default, otherwise wrapped by such middleware.

0 comments on commit 4bc77b3

Please sign in to comment.