我是python的初学者,在我的tkinter中,我有一个总共有4个选项的选项菜单。在
选项菜单# create tk variable
self.timervar = tk.StringVar(root)
# dropdown dictionary
self.timerDict = {"-", "5 seconds", "10 seconds", "15 seconds"}
self.timervar.set("-") #
# timer dropdown menu
self.timer_option = tk.OptionMenu(root, self.timervar, *self.timerDict, command=self.req_timer)
self.timer_option.grid(row=1, column=3, columnspan=2, padx=3, pady=3)
根据该选项,函数将每隔x分钟运行一次。当我切换到另一个选项时,该函数的apscheduler作业将被删除,并将启动一个新作业。在
apscheduler
^{pr2}$
但在我的例子中,一旦apscheduler作业开始运行,即使我切换到另一个应该删除作业的选项,它也不会停止。这是工作的累赘。所以如果我选择5 seconds选项,它将正常运行。但是如果我切换到10 seconds选项,它将在5 seconds选项之上运行10 seconds选项。因为这两个选项使用相同的函数,所以当5秒和10秒重合时,会得到两次相同的结果。在
我试过这个,不管有没有工作id,结果都一样。在
这些是结果Connecting to port... #
Successfully connected to port 9998
Successfully connected to port 9999
Sending request 1 ...
Received reply 1 [ Sensor: 6 :: Data: 123456789 :: Client: 9100 ]
Sending request 2 ...
Received reply 2 [ Sensor: 7 :: Data: 987654321 :: Client: 9101 ]
Connecting to port... #
Successfully connected to port 9998
Successfully connected to port 9999
Sending request 1 ...
Connecting to port...
Successfully connected to port 9998
Successfully connected to port 9999
Sending request 1 ...
Received reply 1 [ Sensor: 6 :: Data: 123456789 :: Client: 9100 ]
Sending request 2 ...
Received reply 1 [ Sensor: 6 :: Data: 123456789 :: Client: 9100 ]
Sending request 2 ...
Received reply 2 [ Sensor: 7 :: Data: 987654321 :: Client: 9101 ]
Received reply 2 [ Sensor: 7 :: Data: 987654321 :: Client: 9101 ]
Connecting to port...
Successfully connected to port 9998
Successfully connected to port 9999
Sending request 1 ...
Received reply 1 [ Sensor: 6 :: Data: 123456789 :: Client: 9100 ] #
Execution of job "MainApplication.req_client (trigger: cron[second='*/5'], next run at: 2017-12-29 16:34:30 +08)" skipped: maximum number of running instances reached (1)
Execution of job "MainApplication.req_client (trigger: cron[second='*/5'], next run at: 2017-12-29 16:34:35 +08)" skipped: maximum number of running instances reached (1)
[Cancelled]
我的代码出了什么问题(可能是所有的问题),如何让它按预期运行?在