利用flask自帶的werkzeug模塊實現
# 監控腳本
# 首先需要 pip install flask
# pymonitor
.
py
def
run_with_reloader
(
main_func
,
args
=
(
)
,
kwargs
=
None
,
extra_files
=
None
,
interval
=
1
,
reloader_type
=
'auto'
)
:
""
"Run the given function in an independent python interpreter."
""
import
os
import
sys
import
signal
import
threading
from
werkzeug
.
_reloader
import
reloader_loops
reloader
=
reloader_loops
[
reloader_type
]
(
extra_files
,
interval
)
signal
.
signal
(
signal
.
SIGTERM
,
lambda
*
args
:
sys
.
exit
(
0
)
)
try
:
if
os
.
environ
.
get
(
'WERKZEUG_RUN_MAIN'
)
==
'true'
:
t
=
threading
.
Thread
(
target
=
main_func
,
args
=
args
,
kwargs
=
kwargs
)
t
.
setDaemon
(
True
)
t
.
start
(
)
reloader
.
run
(
)
else
:
sys
.
exit
(
reloader
.
restart_with_reloader
(
)
)
except KeyboardInterrupt
:
pass
# 運行腳本
import
time
from
pymonitor
import
run_with_reloader
def
main
(
name
,
age
)
:
while
True
:
print
(
"hello, "
,
name
,
'!'
)
time
.
sleep
(
2
)
print
(
age
)
if
__name__
==
'__main__'
:
run_with_reloader
(
main
,
args
=
(
'man'
,
20
)
)
參考鏈接: https://fuyunliu.github.io/2018/03/09/python-reloader/
更多文章、技術交流、商務合作、聯系博主
微信掃碼或搜索:z360901061

微信掃一掃加我為好友
QQ號聯系: 360901061
您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。
【本文對您有幫助就好】元
