nohup 执行 python 程序 , 以及 print 无法输出问题
来源:互联网 发布:hao123网络连接错误 编辑:程序博客网 时间:2024/09/21 06:33
这里的测试环境为 MacOS
一. python 文件
建立 test.py 文件,其代码如下 :
# coding:utf-8 import time while True: # 每隔 2 秒钟打印一次字符串 time.sleep(2) print('hello, python...')
二. shell 脚本文件
建立 test.sh 文件,其代码如下 :
#!/bin/bashecho "begin."nohup python test.py > nohup.out 2>&1 &echo "end."
修改该 test.sh 文件使之具有执行权限 :
# chmod +x ./test.sh
三. 执行脚本启动 nohup ,以及 python 内部 print 无法输出问题
执行 shell 脚本 :
# ./test.sh
该目录下会多出一个文件 nohup.out , 此时目录下有三个文件 test.sh test.py nohup.out ,
但是发现 nohup.out 中显示不出来 python 程序中 print 的内容,
这是因为 python 输出有缓冲,使得 nohup.out 中不能马上有内容
此时,可以使用 python 的 -u 参数,使得 python 不启用缓冲,即 test.sh 脚本改为 :
#!/bin/bashecho "begin."nohup python -u test.py > nohup.out 2>&1 &echo "end."
四. 关闭 nohup 启动的 python 程序
查找 python 进程 :
# ps
显示如下 :
PID TTY TIME CMD
2986 ttys001 0:00.47 -bash
8409 ttys001 0:00.02 python -u test.py
根据进程 ID , kill 掉该 python 进程# kill -9 8409
阅读全文
0 0
- nohup 执行 python 程序 , 以及 print 无法输出问题
- 用nohup执行python程序时,print无法输出
- 用nohup执行python程序时,print无法输出
- 用nohup执行python程序时,print无法输出
- 用nohup执行python程序时,print无法输出
- nohup命令以及ssh断开之后继续执行程序
- Python的print输出中文对齐问题
- linux nohup python 后台运行无输出问题
- python 的print输出
- Python print 格式化输出
- python print输出中文
- python print格式化输出
- python print格式化输出
- Python print格式化输出
- python print格式化输出
- linux后台执行程序,& nohup
- nohup让程序后台执行
- python print以及%格式化
- KindEditor 无法设置内容解决办法
- 【答疑】非科班出身的前端如何学好Node.js?
- Linux(CentOS7)安装MySQL-5.7
- 汽车通信协议
- 阿里云https配置,nginx多证书配置
- nohup 执行 python 程序 , 以及 print 无法输出问题
- cmake配置
- js获取userAgent中操作系统版本
- OkHttp的使用
- 字符串全排列
- 手把手教你玩转Maven
- QT QNetworkDatagram类
- Wannafly模拟赛4 D Fancy Signal Translate(字典树)
- #数据结构