From e520121685d5a071b176d9ea4227fa0cc3584c24 Mon Sep 17 00:00:00 2001 From: lxgr-linux Date: Tue, 12 Nov 2024 03:16:25 +0100 Subject: [PATCH] feat(#267): Fixed evil race condition in bs_rpc --- bs_rpc/__init__.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/bs_rpc/__init__.py b/bs_rpc/__init__.py index 93012a9e..1d2e7ee7 100644 --- a/bs_rpc/__init__.py +++ b/bs_rpc/__init__.py @@ -1,5 +1,4 @@ import json -import logging import threading import time @@ -48,19 +47,19 @@ def __new_call_id(self): return call_id def call_for_response(self, body: Body) -> Body: - call_id = self.__new_call_id() ch = Channel() - self.__send(body, call_id, Method.CALL_FOR_RESPONSE) + call_id = self.__new_call_id() self.calls[call_id] = ch + self.__send(body, call_id, Method.CALL_FOR_RESPONSE) call = ch.listen() del self.calls[call_id] return call def call_for_responses(self, body: Body) -> ChannelGenerator: - call_id = self.__new_call_id() ch = Channel() - self.__send(body, call_id, Method.CALL_FOR_RESPONSES) + call_id = self.__new_call_id() self.calls[call_id] = ch + self.__send(body, call_id, Method.CALL_FOR_RESPONSES) def close_fn(): del self.calls[call_id]