后台守护进程使用python时间时踩的坑

后台守护进程用python使用time时踩的坑

后台守护进程 使用python时间使用坑

  • 待引入包内容 ttime.py
import time
c = time.strftime('%Y%m%d', time.localtime())
print(c)
  • 后台守护 changzhutest.py
from ttime import c
import time

while True:
    print("timenow",time.strftime("%Y-%m-%d %H:%M:%s",time.localtime()))
    print('now:',time.strftime('%Y%m%d', time.localtime()))
    print('import C :',c)
    time.sleep(1200)
  • 执行

python -u changzhutest.py >test.log &

  • 执行后内容输出

说明:代码中引入的时间没有问题,使用import导入的变量获取的时间没有变化

('timenow', '2020-08-13 23:46:1597333602')
('now:', '20200813')
('import C :', '20200813')
('timenow', '2020-08-14 00:06:1597334802')
('now:', '20200814')
('import C :', '20200813')

结论

使用应用做后台守护时要注意:import过来的数据使用time获取时需要注意,尽量在程序执行代码中使用,而不是导入变量中。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值