python-3.x - ray: python does not print after time.sleep
问题描述
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
解决方案
ray讨论区也有提到:
这是当前光线中的一个问题。等待下一个版本。只需标记日期 2021 年 3 月 11 日。雷 1.0.1 发布
推荐阅读
- ios - VolumeView 未显示 Airplay 按钮
- phpunit - 使用 phpunit 自我更新 *.phpt 测试?
- node.js - 安装依赖项会导致 npm ERR!无法读取未定义的属性“解决”
- python - 为什么我使用 .isdigit() 函数时会返回错误?
- javascript - 键盘未检测到输入
- python - 在测试函数python中有一个if语句
- html - 基于 HTML 内容构建 PDF 页面以适应 A4 大小
- wordpress - 如何为 flatpickr/Ninja Forms 设置 minDate?
- c++ - 链接器命令失败 - OSX 上的 C++
- jupyter-notebook - Jupyternotebook 显示问题