Python後台執行不啟用快取

2021-10-06 15:36:01 字數 688 閱讀 6492

python後台執行不啟用快取

1、執行時加-u引數,如 # python3 -u test.py >> test.log &

用man檢視python的-u引數,說明如下:

force stdin, stdout and stderr to be totally unbuffered. on systems where it matters, also put stdin, stdout and stderr in binary mode. note that there is internal buffering in xreadlines(), readlines() and file-object iterators (「for line in sys.stdin」) which is not influenced by this option. to work around this, you will want to use 「sys.stdin.readline()」 inside a 「while 1:」 loop.
強制stdin,stdout和stderr完全不緩衝。

2、在不要緩衝的每一次print後面新增sys.stdout.flush()函式

3、指令碼頭部新增-u,如#!/usr/local/bin/python -u,道理同方法1

4、新增環境變數 pythonunbuffered=1

Python後台執行不啟用快取

1 執行時加 u引數,如 python3 u test.py test.log 用man檢視python的 u引數,說明如下 force stdin,stdout and stderr to be totally unbuffered.on systems where it matters,also...

python 後台執行

該方法時使用pm2程序管理器來執行python程式的,因為pm2管理器是基於node.js的,所以要先安裝node.js 安裝node 然後安裝pm2 最後使用pm2命令執行python程式就行了 如果想開機自啟動程式 linux系統使用上面的命令就行了 windows下使用批處理命令執行程式,然後...

執行python指令碼後台執行

加了 以後可以使指令碼在後台執行,這樣的話你就可以繼續工作了。但是有乙個問題就是你關閉終端連線後,指令碼會停止執行 python3 run.py dev null 2 1 nohup python3 run.py dev null 2 1 注意print有輸出緩衝,使用 u引數,使得python不啟...