远程电脑的python后台执行

  最近为一个程序写守护程序,使用python中Timer实现。过程大致如下:

from threading import Timer

def task():
    print("")
    t = Timer(10, task)
    t.start()

t = Timer(10, task)
    t.start()

  windows下后台执行python,可以使用“pythonw task.py"。本来想把日志重定向到文件,结果” > task.log"参数未起效。参考https://blog.51cto.com/u_15127495/2675037,将print改成logger达到目的。

  为了达到关闭远程连接后,pythonw不会被kill掉,所以需要在pwershell(管理员)中执行"pythonw task.py"。

  可能用到的命令(在pwershell(管理员)中执行):

  查看进程:tasklist | findstr pythonw

  关闭进程:taskkill /f /pid 进程ID

原文地址:https://www.cnblogs.com/hghhe/p/15305116.html