I'd just like to share a few hard-won tips for writing pulsar functions in python.

(1) Pulsar is hard-wired to start "python" not "python3".  I hope this will change <https://github.com/apache/pulsar/issues/5518>, but until then there is a very risky workaround on Ubuntu:

|sudo update-alternatives --install /usr/bin/python python /usr/bin/python3 10|

Only do this on a system where python(2) is *not* installed and you are sure you will never install it - not even as a dependency of some other package.  If it's a VM dedicated to pulsar you may be OK.


(2) If a python function crashes at startup, you won't see its stderr output from the "localrun" command or the pulsar daemon. But you *will* find it logged to

apache-pulsar-2.4.1/logs/functions/<tenant>/<namespace>/<function>/<function>-<n>.log


(3) If you have a python function which includes a class, e.g. /home/ubuntu/func1.py contains class FirstFunction, then you have to start it like this:

        --py /home/ubuntu/func1.py --class func1.FirstFunction

(that is, "func1" appears twice).  I didn't see any example like this in the documentation, and you don't get much help if you get it wrong! :-)  It works by adding the dirname (/home/ubuntu in this case) to sys.path.

Hope this helps someone else.

Cheers,

Brian.

Reply via email to