Skip to content

Commit

Permalink
[fix] use a lock in LispCallbackObject too
Browse files Browse the repository at this point in the history
  • Loading branch information
digikar99 committed Apr 24, 2024
1 parent 0266a09 commit d02365a
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions py4cl.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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):
Expand Down

0 comments on commit d02365a

Please sign in to comment.