As AI suggests, we have to add flush = True to the py5 print() calls, eg print("Hello py5 world!", flush = True) then it will work as expected.
Alternate Approach:
Use ProcessBuilder with builder.environment().put("PYTHONUNBUFFERED", "TRUE"); This also works and obviates the need to add flush=True to every print() in py5.