|
|
bc7ada |
From 780394e905186c9c95a8e90aa5107f698a5b1f5b Mon Sep 17 00:00:00 2001
|
|
|
bc7ada |
From: Link Dupont <link@sub-pop.net>
|
|
|
bc7ada |
Date: Wed, 16 Nov 2022 13:35:12 -0500
|
|
|
bc7ada |
Subject: [PATCH] fix: ensure _run_data is called on a thread
|
|
|
bc7ada |
|
|
|
bc7ada |
_run_data is not async-aware, so declaring it as an async function and
|
|
|
bc7ada |
running it in an event loop results in synchronous execution of the
|
|
|
bc7ada |
entire function. This means the Send function only returns once the
|
|
|
bc7ada |
entire _run_data function has completed. Running it on the event loop
|
|
|
bc7ada |
using run_in_executor runs the function call in a thread executor pool,
|
|
|
bc7ada |
ensuring that it doesn't block the calling thread. This is a fairly
|
|
|
bc7ada |
naive solution; a better implementation might be able to pass a future
|
|
|
bc7ada |
into _run_data, immediately fulfill that future, let the calling
|
|
|
bc7ada |
function (Send) return the RPC receipt, and continue running _run_data.
|
|
|
bc7ada |
|
|
|
bc7ada |
(cherry picked from commit 03e7385199140fde0686f1031459f7f61e5f735b)
|
|
|
bc7ada |
|
|
|
bc7ada |
Resolves: RHBZ#2142992
|
|
|
bc7ada |
|
|
|
bc7ada |
Signed-off-by: Link Dupont <link@sub-pop.net>
|
|
|
bc7ada |
---
|
|
|
bc7ada |
rhc_worker_playbook/server.py | 5 +++--
|
|
|
bc7ada |
1 file changed, 3 insertions(+), 2 deletions(-)
|
|
|
bc7ada |
|
|
|
bc7ada |
diff --git a/rhc_worker_playbook/server.py b/rhc_worker_playbook/server.py
|
|
|
bc7ada |
index e41482d..cf282c5 100644
|
|
|
bc7ada |
--- a/rhc_worker_playbook/server.py
|
|
|
bc7ada |
+++ b/rhc_worker_playbook/server.py
|
|
|
bc7ada |
@@ -17,6 +17,7 @@ import json
|
|
|
bc7ada |
import uuid
|
|
|
bc7ada |
import atexit
|
|
|
bc7ada |
import asyncio
|
|
|
bc7ada |
+import functools
|
|
|
bc7ada |
from subprocess import Popen, PIPE
|
|
|
bc7ada |
from requests import Request
|
|
|
bc7ada |
from concurrent import futures
|
|
|
bc7ada |
@@ -138,11 +139,11 @@ class WorkerService(yggdrasil_pb2_grpc.WorkerServicer):
|
|
|
bc7ada |
'''
|
|
|
bc7ada |
|
|
|
bc7ada |
loop = asyncio.new_event_loop()
|
|
|
bc7ada |
- loop.run_until_complete(self._run_data(request))
|
|
|
bc7ada |
+ loop.run_in_executor(executor=None, func=functools.partial(self._run_data, request))
|
|
|
bc7ada |
|
|
|
bc7ada |
return yggdrasil_pb2.Receipt()
|
|
|
bc7ada |
|
|
|
bc7ada |
- async def _run_data(self, request):
|
|
|
bc7ada |
+ def _run_data(self, request):
|
|
|
bc7ada |
# load configuration
|
|
|
bc7ada |
config = _loadConfig()
|
|
|
bc7ada |
|