You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I need to pass some Julia functions as callbacks to a Python function. I've scoured the documentation but I can't figure out how to pass callbacks to Python.
defsubscribe(self, topic, qos, callback=None):
future=Future()
packet_id=0ifcallback:
defcallback_wrapper(topic, payload, dup, qos, retain):
try:
callback(topic=topic, payload=payload, dup=dup, qos=QoS(qos), retain=retain)
exceptTypeError:
# This callback used to have fewer args.# Try again, passing only those those args, to cover case where# user function failed to take forward-compatibility **kwargs.callback(topic=topic, payload=payload)
else:
callback_wrapper=Nonedefsuback(packet_id, topic, qos, error_code):
iferror_code:
future.set_exception(awscrt.exceptions.from_code(error_code))
else:
qos=_try_qos(qos)
ifqosisNone:
future.set_exception(SubscribeError(topic))
else:
future.set_result(dict(
packet_id=packet_id,
topic=topic,
qos=qos,
))
try:
assertcallable(callback) orcallbackisNoneassertisinstance(qos, QoS)
packet_id=_awscrt.mqtt_client_connection_subscribe(
self._binding, topic, qos.value, callback_wrapper, suback)
exceptExceptionase:
future.set_exception(e)
returnfuture, packet_id
I can change if callback: to if callback is not None: for the same effect, though 1) I don't want to start maintaining patches for my dependencies and 2) this method of passing callbacks leads to segfaults later on when they are invoked, so I think I am just doing something wrong.
Julia Version 1.7.2
Commit bf53498635 (2022-02-06 15:21 UTC)
Platform Info:
OS: Linux (x86_64-pc-linux-gnu)
CPU: Intel(R) Core(TM) i9-9900K CPU @ 3.60GHz
WORD_SIZE: 64
LIBM: libopenlibm
LLVM: libLLVM-12.0.1 (ORCJIT, skylake)
PythonCall v0.8.0
The text was updated successfully, but these errors were encountered:
Ok so the approach looks fine, but indeed there is a bug in getting the truthiness of a wrapped Julia value, which I'll fix.
You can also pass pyfunc(f) instead of the function f. The difference is that the arguments passed to pyfunc(f) are always Py (which is normally appropriate for callback functions) whereas the arguments to f are converted first. As a handy side effect, pyfunc(f) shouldn't have the truthy bug.
I'll need a MWE if you want me to look at the segfaults.
As for the segfault, I'm happy to provide the full code, though it relies on you having certain AWS resources. Not sure if you want to provision those. If you don't, I'm also happy to grant you access to my resources so that you can test with them. I'd want to transfer the details in a secure way, of course. Let me know if either option interests you.
I need to pass some Julia functions as callbacks to a Python function. I've scoured the documentation but I can't figure out how to pass callbacks to Python.
My code:
The error I get:
This is the Python code of my dependency:
I can change
if callback:
toif callback is not None:
for the same effect, though 1) I don't want to start maintaining patches for my dependencies and 2) this method of passing callbacks leads to segfaults later on when they are invoked, so I think I am just doing something wrong.The text was updated successfully, but these errors were encountered: