From d02365acbee98ddf65f54ce79e1f23d5aef27269 Mon Sep 17 00:00:00 2001 From: digikar Date: Thu, 25 Apr 2024 00:06:25 +0530 Subject: [PATCH] [fix] use a lock in LispCallbackObject too --- py4cl.py | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/py4cl.py b/py4cl.py index 3e9f1e43..d7f8cfea 100644 --- a/py4cl.py +++ b/py4cl.py @@ -82,6 +82,7 @@ class LispCallbackObject (object): An object is used rather than a lambda, so that the lifetime can be monitoried, and the function removed from a hash map """ + lisp_callback_lock = threading.RLock() def __init__(self, handle): """ handle A number, used to refer to the object in Lisp @@ -108,16 +109,17 @@ def __call__(self, *args, **kwargs): for key, value in kwargs.items(): allargs += (Symbol(":"+str(key)), value) - old_return_values = return_values # Save to restore after - try: - return_values = 0 - send_value("c", (self.handle, allargs)) - finally: - return_values = old_return_values - - # Wait for a value to be returned. - # Note that the lisp function may call python before returning - return message_dispatch_loop() + with LispCallbackObject.lisp_callback_lock: + old_return_values = return_values # Save to restore after + try: + return_values = 0 + send_value("c", (self.handle, allargs)) + finally: + return_values = old_return_values + + # Wait for a value to be returned. + # Note that the lisp function may call python before returning + return message_dispatch_loop() class UnknownLispObject (object):