0

I have hardware running on nodejs, and I have written machine learning code in python3. I want to call python3 program from nodejs (javascript) and pass data as arguments to python program.

I have found some of the methods like using spawn, python-shell, etc. which calls python by creating a child process.

But I want to call python from the parent process itself, without creating a child process. Means, only process, that is parent nodejs process should be running.

test.py

def someFunction():
  #some code here
  #print the arguments received.

someFunction ()

test.js

call test.py from this test.js and need to pass arguments to python program as well.
call test.py with arguments as ('xyz', 'abc')

I expect the output: xyz abc

Didn't find any way to call without creating and starting child process.

1
  • 1
    Python is an interpreted language, I don't think there is a way to run uncompiled pure python code without starting an interpreter process. Commented Jun 20, 2019 at 9:32

1 Answer 1

1

You can't. You're spawning an external program, that needs a process of its own.


OK, that's not entirely true. You could write a complete Python interpreter or a virtual machine (which you could run an OS in and then run Python in that) in JavaScript and then you could run it entirely within the Node.js process … but that would be a huge amount of work.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.