From 3a734718d5c2bb7ed57ad612e2c7158736d1a650 Mon Sep 17 00:00:00 2001 From: Andrew Meyer <75644492+ameyer-rigetti@users.noreply.github.com> Date: Mon, 19 Apr 2021 10:39:47 -0700 Subject: [PATCH] Fixes thread-safety issue in Message.types() (#151) * Fixes thread-safety issue in Message.types() * Bump version to 3.9.1 --- VERSION.txt | 2 +- rpcq/_base.py | 15 +++++++-------- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/VERSION.txt b/VERSION.txt index a5c4c76..6bd1074 100644 --- a/VERSION.txt +++ b/VERSION.txt @@ -1 +1 @@ -3.9.0 +3.9.1 diff --git a/rpcq/_base.py b/rpcq/_base.py index 36e68c0..ac35a76 100644 --- a/rpcq/_base.py +++ b/rpcq/_base.py @@ -109,7 +109,7 @@ def __eq__(self, other): def __hash__(self): return hash((self.__class__, astuple(self))) - _types = None + _types = {} @staticmethod def types(): @@ -120,13 +120,12 @@ def types(): :return: A dictionary of ``Message`` types. :rtype: Dict[str,type] """ - if Message._types is None: - Message._types = {} - classes_to_process = [Message] - while classes_to_process: - atom = classes_to_process.pop() - classes_to_process += atom.__subclasses__() - Message._types[atom.__name__] = (atom, inspect.getfullargspec(atom.__init__).args) + classes_to_process = [Message] + while classes_to_process: + atom = classes_to_process.pop() + classes_to_process += atom.__subclasses__() + Message._types[atom.__name__] = (atom, inspect.getfullargspec(atom.__init__).args) + return Message._types