如何解决ray:python 在 time.sleep 后不打印
我使用的是centos 8.2,python 3.6.8,ray 1.0.1 /3/,我的python源代码写在/1/,结果显示在/2/,它只适用于第一次打印,但是它不适用于第二次打印和第三次打印。 link 说我只是在 print 子句中加入了flush参数,但它不起作用。
/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]$
[已编辑,添加更多]
如果我删除 time.sleep,则打印正常。 time.sleep 做了什么使打印消失?
/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
解决方法
在ray讨论论坛中也提到了:
这是当前光线的问题。等待下一个版本。只需将日期标记为 2021 年 3 月 11 日。 Ray 1.0.1 发布
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。