0

So I am using the python library Naked and am using their provided execute_js function to execute a NodeJS file from my python script. However, my JavaScript file outputs first and then my python outputs show up. I'm not sure if Javascript is being executed first or not but I need my python outputs to be in sequence. For example:

print("Start of file") execute_js('helloworld.js') print("End of File")

Outputs as this in the console:

Hello World Start of file End of file

Is there a way to fix this?

1 Answers1

0

You will need to flush the output of Python from its buffers:

print("Start of file")
sys.stdout.flush()
execute_js('helloworld.js')
print("End of File")

This should make the Python output appear on the stdout filehandle before the Javascript output gets there.

See also

How to flush output of print function?

Why doesn't python3's print statement flush output when end keyword is specified?

Corion
  • 3,855
  • 1
  • 17
  • 27