线程不更新模块时间
threading not update module time
我是 python 的新手,我在序列时间为 运行 编写了一个简单的代码,并在触发时发送电子邮件。
我使用线程计时器进行计数并导入 outbound.py(使用导入日期时间)只是为了清理主脚本,因此它不会在 main.py 中包含电子邮件脚本。然而,当收到第一封电子邮件时,消息时间正确反映,但下一封电子邮件与第一封电子邮件保持相同时间。
下面是 main.py 股票
import threading
from outbound import outbound
def run ():
threading.Timer(10,run).start()
outbound()
run()
outbound.py 股票
from datetime import datetime
now=datetime.now()
dt_string = now.strftime("%d/%m/%Y %H:%M:%S")
def outbound():
print (dt_string)
您在导入模块时创建了 dt_string
,并且再也没有更新过它。将字符串初始化移动到函数体中。
def outbound():
dt_string = datetime.now().strftime("%d/%m/%Y %H:%M:%S")
print (dt_string)
我是 python 的新手,我在序列时间为 运行 编写了一个简单的代码,并在触发时发送电子邮件。 我使用线程计时器进行计数并导入 outbound.py(使用导入日期时间)只是为了清理主脚本,因此它不会在 main.py 中包含电子邮件脚本。然而,当收到第一封电子邮件时,消息时间正确反映,但下一封电子邮件与第一封电子邮件保持相同时间。
下面是 main.py 股票
import threading
from outbound import outbound
def run ():
threading.Timer(10,run).start()
outbound()
run()
outbound.py 股票
from datetime import datetime
now=datetime.now()
dt_string = now.strftime("%d/%m/%Y %H:%M:%S")
def outbound():
print (dt_string)
您在导入模块时创建了 dt_string
,并且再也没有更新过它。将字符串初始化移动到函数体中。
def outbound():
dt_string = datetime.now().strftime("%d/%m/%Y %H:%M:%S")
print (dt_string)