This issue tracker has been migrated to GitHub ,
and is currently read-only.
For more information,
see the GitHub FAQs in the Python's Developer Guide.
Created on 2014年01月05日 03:00 by julian, last changed 2022年04月11日 14:57 by admin.
| Messages (11) | |||
|---|---|---|---|
| msg207336 - (view) | Author: julian (julian) | Date: 2014年01月05日 03:00 | |
Events added after the scheduler is running, with a delay value before the next event, do not run at the correct time. import sched import time import threading def event( eventNum ): print( 'event', eventNum, time.time() ) s = sched.scheduler() s.enter( 0,1,event, (0,) ) s.enter(10,1,event, (1,) ) t = threading.Thread( target = s.run ) t.start() s.enter( 5,1,event, (2,) ) OUTPUT event 0 1388890197.7716181 event 2 1388890207.7340584 event 1 1388890207.7347224 |
|||
| msg207343 - (view) | Author: R. David Murray (r.david.murray) * (Python committer) | Date: 2014年01月05日 03:40 | |
I believe this is a duplicate of issue 16165, which has already been fixed. |
|||
| msg207391 - (view) | Author: julian (julian) | Date: 2014年01月05日 19:04 | |
i saw that issue before i submitted this one, but it says it was fixed a year ago. i assumed a patch from a year ago would be in 3.3.1. when i see an issue closed with a patch accepted, how do i determine which python version will contain that patch? |
|||
| msg207405 - (view) | Author: R. David Murray (r.david.murray) * (Python committer) | Date: 2014年01月05日 22:27 | |
Search for the issue number in Misc/NEWS. It looks like it was indeed included in 3.3.1. Can you figure out why that fix didn't fix your problem? |
|||
| msg207406 - (view) | Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) | Date: 2014年01月05日 23:00 | |
This is because the scheduler already has executed first event and slept on delaying second event before you have added third event. This is unavoidable for this implementation. sched.scheduler can't be waked when sleep. |
|||
| msg207407 - (view) | Author: julian (julian) | Date: 2014年01月05日 23:05 | |
i looks like a different issue. 16165 says you can't add events while the scheduler is running. in my case, i can add them, but they don't run at the correct time. i'll guess at what the problem is... when you start the scheduler, the thread sleeps until the first scheduled event. when you add an event after the scheduler is running, the scheduler doesn't re-evaluate how long it should sleep. sched.enter(), sched.enterabs(), and sched.cancel() should probably send a signal to the scheduler thread to recalculate the time of the next event. |
|||
| msg207408 - (view) | Author: julian (julian) | Date: 2014年01月05日 23:20 | |
ok, makes sense. can we put a note in the manual about this limitation? |
|||
| msg207543 - (view) | Author: Giampaolo Rodola' (giampaolo.rodola) * (Python committer) | Date: 2014年01月07日 14:54 | |
I don't think this should be documented as personally I wouldn't expect this use case to be working in the first place. |
|||
| msg244345 - (view) | Author: Josh Rosenberg (josh.r) * (Python triager) | Date: 2015年05月28日 20:52 | |
Why would you not expect this to work in the first place? I'd think a relatively simple use case for schedulers is using a single thread to do the work of a Timer instead of spawning a thread for every Timer. In that sort of use case, the "timer worker" is constantly pulling tasks and other thread(s) are adding them; for an empty event queue, if thread A adds a task 'a' that delays for 10 minutes and thread B adds a task 'b' that delays for 1 minute, the time at which task 'b' executes changes dramatically based on which thread squeaks out a win on the race to insert into the scheduler queue. As long as task 'a' wins the race, a million other tasks could be scheduled to run before it, but all of them will be stuck behind task 'a' no matter their priority or delay. It should be possible to fix this without too much trouble (and without polling loops), but it would require scheduler to remove the option to customize delayfunc; you'd change the scheduler's RLock to a Condition, have mutations to the event queue notify the Condition, and the run method would replace sleeping outside the locked scope with a wait w/timeout inside it. The only thing blocking a fix for this is backwards compatibility. If people are okay with breaking that, I'll happily contribute a patch, but I want some indication of whether back compat can be sacrificed to make sched actually useful in threaded contexts. |
|||
| msg360285 - (view) | Author: Ryan Govostes (rgov) | Date: 2020年01月20日 03:26 | |
This absolutely should be documented. If adding an earlier event is not supported then it should raise an exception. Appearing the enqueue the event but not triggering the callback is especially confusing. It may be obvious behavior to someone who has spent time developing this module or working with it but not to someone who just wants to, e.g., build an alarm clock or calendar app. |
|||
| msg407107 - (view) | Author: Irit Katriel (iritkatriel) * (Python committer) | Date: 2021年11月26日 23:29 | |
Reproduced on 3.11. |
|||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2022年04月11日 14:57:56 | admin | set | github: 64325 |
| 2021年11月27日 08:59:08 | iritkatriel | set | title: sched doesn't handle events added after scheduler starts as expected -> sched doesn't handle at the expected time those events which are added after scheduler starts |
| 2021年11月26日 23:30:42 | iritkatriel | set | title: sched doesn't handle events added after scheduler starts -> sched doesn't handle events added after scheduler starts as expected |
| 2021年11月26日 23:30:08 | iritkatriel | set | components: + Library (Lib) |
| 2021年11月26日 23:29:56 | iritkatriel | set | nosy:
+ iritkatriel messages: + msg407107 versions: + Python 3.11, - Python 3.3 |
| 2020年01月20日 03:26:42 | rgov | set | nosy:
+ rgov messages: + msg360285 |
| 2015年05月28日 20:52:51 | josh.r | set | nosy:
+ josh.r messages: + msg244345 |
| 2014年01月07日 14:54:43 | giampaolo.rodola | set | nosy:
+ giampaolo.rodola messages: + msg207543 |
| 2014年01月05日 23:20:05 | julian | set | messages: + msg207408 |
| 2014年01月05日 23:05:26 | julian | set | messages: + msg207407 |
| 2014年01月05日 23:00:33 | serhiy.storchaka | set | messages: + msg207406 |
| 2014年01月05日 22:28:47 | r.david.murray | set | nosy:
+ serhiy.storchaka |
| 2014年01月05日 22:27:45 | r.david.murray | set | status: closed -> open superseder: sched.scheduler.run() blocks scheduler -> messages: + msg207405 resolution: duplicate -> stage: resolved -> |
| 2014年01月05日 19:04:58 | julian | set | messages: + msg207391 |
| 2014年01月05日 03:40:07 | r.david.murray | set | status: open -> closed superseder: sched.scheduler.run() blocks scheduler nosy: + r.david.murray messages: + msg207343 resolution: duplicate stage: resolved |
| 2014年01月05日 03:00:23 | julian | create | |