I am using centos 8.2, python 3.6.8, ray 1.0.1 /3/, I have python souce code written in /1/, and result is shown in /2/, it only works for first print, but it does not work for second print and third print. link says I just put flush argument in print clause, but it does not work.
/1/
import ray
import time
ray.init();
@ray.remote
def f():
a = 3;
print("before print",flush=True);
time.sleep(1);
print("after print",flush=True);
time.sleep(2);
print("end",flush=True);
return 1;
f.remote()
f.remote()
f.remote()
/2/
[sjj@localhost exer1Sleep]$ export PYTHONUNBUFFERED=TRUE
[sjj@localhost exer1Sleep]$ python3 raySleep.py
2021-03-10 14:26:15,322 INFO services.py:1092 -- View the Ray dashboard at http://127.0.0.1:8265
(pid=42437) before print
(pid=42438) before print
(pid=42442) before print
/3/
[sjj@localhost exer1Sleep]$ python3 --version
Python 3.6.8
[sjj@localhost exer1Sleep]$ ray --version
ray, version 1.0.1.post1
[sjj@localhost exer1Sleep]$
[edited, add more]
If I remove time.sleep, the print works ok. What does time.sleep make so that print disappears?
/4/
import ray
import time
ray.init();
@ray.remote
def f():
a = 3;
print("before print",flush=True);
print("after print",flush=True);
print("end",flush=True);
return 1;
f.remote()
f.remote()
f.remote()
/5/
[sjj@localhost exer1Sleep]$ python3 raySleepWithout.py
2021-03-11 11:34:07,933 INFO services.py:1092 -- View the Ray dashboard at http://127.0.0.1:8265
(pid=45246) before print
(pid=45246) after print
(pid=45246) end
(pid=45242) before print
(pid=45242) after print
(pid=45242) end
(pid=45245) before print
(pid=45245) after print
(pid=45245) end