繁体   English   中英

为什么 crontab 总是用新的 PID 重新启动我的 python 脚本

[英]Why does crontab always restart my python script with a new PID

我有一个 python3 脚本,想在重启后自动启动它。 它正在启动,但它总是以一个新的 PID 开始,我用 ps aux 进行了检查。 如果我通过终端启动文件,它只是在同一个 PID 中运行。

我在 crontab 中使用了 @reboot /usr/bin/python3 /path/myFile.py

import sys

from cryptography import x509
sys.path.insert(0, "..")
import time


from opcua import ua, Server


if __name__ == "__main__":

    # setup our server
    server = Server()
    server.set_endpoint("opc.tcp://0.0.0.0:4842/freeopcua/server/")

    # setup our own namespace, not really necessary but should as spec
    uri = "http://examples.freeopcua.github.io"
    idx = server.register_namespace(uri)


    # get Objects node, this is where we should put our nodes
    objects = server.get_objects_node()

    # populating our address space
    myobj = objects.add_object(idx, "MyObject")
    startCali = myobj.add_variable(idx, "Start Calibration", True)
    brigthness = myobj.add_variable(idx, "Brightneess", 0.0)

    brigthness.set_writable()
    startCali.set_writable()    # Set MyVariable to be writable by clients
    oldstartCalivar = 0
    oldbrightnesss = 1.0
    
   
 

    # starting!
    server.start()
    
    try:
        count = 0
        while True:
            time.sleep(1)
            
            if brigthness.get_value () != oldbrightnesss:
                changeBrightness = "xrandr --output eDP-1 --brightness %f" % (brigthness.get_value()) 
            oldbrightnesss = brigthness.get_value()
                
                     
    finally:
        #close connection, remove subcsriptions, etc
        server.stop()

我用另一种方法解决了它:

https://stackoverflow.com/questions/51025312/start-a-python-script-at-startup-automatically

-->Artsiom Praneuski 的回答

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM