candlerb opened a new issue #5522: localrun fails to load python functions from 
correct file
URL: https://github.com/apache/pulsar/issues/5522
 
 
   **Describe the bug**
   If you try to run a function like this:
   
   ```
   apache-pulsar-2.4.1/bin/pulsar-admin functions localrun ... --py 
/home/ubuntu/func1.py
   ```
   
   Then the function fails to start.  Strace output shows that it's trying to 
read python code from `/home/ubuntu` instead of `/home/ubuntu/func1.py`
   
   **To Reproduce**
   As per #5521 
   
   I have `func1.py` in the current directory:
   
   ```
   $ pwd
   /home/ubuntu
   $ cat func1.py
   from pulsar import Function
   
   class FirstFunction(Function):
       def process(self, item, context):
           log = context.get_logger()
           log.info("Got %r with properties %r" % (item, 
context.get_message_properties()))
   ```
   
   What I originally wanted to do was run it like this:
   
   ```
   $ apache-pulsar-2.4.1/bin/pulsar-admin functions localrun --name womble2 
--inputs my-topic --py func1.py --classname FirstFunction --log-topic pulsar-log
   The specified python file does not exist
   ...
   ```
   
   That's because pulsar-admin changes the working directory, as almost the 
first thing it does.  So instead I gave an absolute path to the function:
   
   ```
   $ apache-pulsar-2.4.1/bin/pulsar-admin functions localrun --name womble2 
--inputs my-topic --py /home/ubuntu/func1.py --classname FirstFunction 
--log-topic pulsar-log
   ```
   
   Pulsar goes into a loop, attempting to start every 30 seconds, but not 
indicating why the python process fails.  (Full session logs in #5521, that 
ticket is about the error output beig discarded)
   
   So I run under strace:
   
   ```
   $ strace -f -s128 apache-pulsar-2.4.1/bin/pulsar-admin functions localrun 
--name womble2 --inputs my-topic --py /home/ubuntu/func1.py --classname 
FirstFunction --log-topic pulsar-log 2>/tmp/strace.out
   ...
   13:14:07.229 [main] INFO  org.apache.pulsar.functions.LocalRunner - 
RuntimeSpawner quit because of
   ^C
   ```
   
   And buried in the strace is the error message:
   
   ```
   $ grep "Failed to import class" /tmp/strace.out
   [pid 17173] write(3, "[2019-10-31 12:48:33 +0000] [INFO] util.py: Failed to 
import class FirstFunction from path /home/ubuntu\n", 104) = 104
   ```
   
   It should be trying to read from `/home/ubuntu/func1.py`
   
   So then I tried moving `func1.py` into the `apache-pulsar-2.4.1` directory, 
and running like this:
   
   ```
   $ strace -s128 -f apache-pulsar-2.4.1/bin/pulsar-admin functions localrun 
--name womble2 --inputs my-topic --py func1.py --classname FirstFunction 
--log-topic pulsar-log 2>/tmp/strace.out
   ```
   
   Now the file it is trying to read from is an empty filename!
   
   ```
   $ grep "Failed to import class" /tmp/strace.out
   [pid 18278] write(3, "[2019-10-31 13:14:07 +0000] [INFO] util.py: Failed to 
import class FirstFunction from path \n", 92) = 92
   ```
   
   **Expected behavior**
   Function to be loaded from the file I specified
   
   **Screenshots**
   See above
   
   **Desktop (please complete the following information):**
    - Ubuntu 18.04
   
   **Additional context**
   N/A

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to