让服务器每晚运行一个命令,就像 python 中的 cron 作业
我在编写服务器程序时遇到了问题。我需要为套接字设置一个超时,该超时将根据套接字签入的时间每天增加。该程序将为表示自服务器首次运行以来传递的日期的变量+1。该变量将乘以 86,400(一天中的秒数)来设置套接字的超时。
我的问题是,有没有办法运行一个 cron 作业,每隔 2 天执行一次脚本的一部分?有问题的服务器具有可以运行此命令的命令。然而,这将涉及手动交互,这很痛苦。那么,在 python 中,有没有办法让它每天凌晨 4:00 运行一个命令,而不用 while 循环锁定程序呢?
I have run into a problem while writing my server program. I need to set a timeout for a socket that will increase every single day depending on when the socket checks in. The program will +1 to a variable that represents the dates passed since when the server is first run. This variable will than be multiplied by 86,400 (The amount of seconds in a day) to set the timeout for the socket.
My question is, is there a way to run a cron job that will execute a part of a script every say, 2 days? The server in question has commands that can run this. However, that would involve manual interaction which is a pain. So, in python is there a way to make it run a command every day at 4:00 am, without locking the program up with a while loop?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要创建一个单独的执行线程来处理要处理的套接字通信。
http://www.devshed.com/c/a/Python/Basic-Threading-in-Python/
You need to create a seperate thread of execution for your socket communication to be handled in.
http://www.devshed.com/c/a/Python/Basic-Threading-in-Python/