python apscheduler tkinter_apscheduler不删除作业

我是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]

我的代码出了什么问题(可能是所有的问题),如何让它按预期运行?在

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值