New submission from mediator42 <h.lensch@lmt.uni-saarland.de>: Hi, I am pretty confident, that the example you put on the Event scheduler page (https://docs.python.org/3.7/library/sched.html) is somehow strange. If the priority argument behave as described, it should print the "keyword" line before the "positional" line, since these events are scheduled for the same time but "keyword" has a higher priority than "positional". When I run this script on my PC it behaves correctly. Best reagrds ---------- assignee: docs@python components: Documentation messages: 325345 nosy: docs@python, mediator42 priority: normal severity: normal status: open title: Event scheduler page example type: behavior versions: Python 3.7 _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue34677> _______________________________________
Change by Roundup Robot <devnull@psf.upfronthosting.co.za>: ---------- keywords: +patch pull_requests: +12588 stage: -> patch review _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue34677> _______________________________________
Karthikeyan Singaravelan <tir.karthi@gmail.com> added the comment: enter takes a relative time and priority is taken into consideration only when time is equal. So in the example enter(0.001, 2) is executed first and there is some delay in executing enter(0.001, 2). You can also view the queue with s.queue which is a heap. So even though they look similar the first call is scheduled earlier than the second one even with lower priority. Your report is correct if the example used enterabs where the time is absolute and then the two events are ordered based on priority with keyword executed first in the heapq used . In your script you can print s.sched and maybe add the same to the report? # enter and s.sched prints different time with positional scheduled to be executed first in time. ➜ cpython git:(master) cat /tmp/bar.py import sched, time s = sched.scheduler(time.time, time.sleep) def print_time(a='default'): print("From print_time", time.time(), a) def print_some_times(): print(time.time()) s.enter(0.001, 2, print_time, argument=('positional',)) s.enter(0.001, 1, print_time, kwargs={'a': 'keyword'}) print(s.queue) s.run() print(time.time()) print_some_times() ➜ cpython git:(master) ./python.exe /tmp/bar.py 1554204002.401897 [Event(time=1554204002.40309, priority=2, action=<function print_time at 0x10e9747e0>, argument=('positional',), kwargs={}), Event(time=1554204002.403158, priority=1, action=<function print_time at 0x10e9747e0>, argument=(), kwargs={'a': 'keyword'})]
From print_time 1554204002.40331 positional From print_time 1554204002.403441 keyword 1554204002.403517
# enterabs and s.sched prints same time with keyword ordered first based on priority with time being equal. ➜ cpython git:(master) cat /tmp/baz.py import sched, time s = sched.scheduler(time.time, time.sleep) def print_time(a='default'): print("From print_time", time.time(), a) def print_some_times(): print(time.time()) s.enterabs(0.001, 2, print_time, argument=('positional',)) s.enterabs(0.001, 1, print_time, kwargs={'a': 'keyword'}) print(s.queue) s.run() print(time.time()) print_some_times() ➜ cpython git:(master) ./python.exe /tmp/baz.py 1554204136.854676 [Event(time=0.001, priority=1, action=<function print_time at 0x1042767e0>, argument=(), kwargs={'a': 'keyword'}), Event(time=0.001, priority=2, action=<function print_time at 0x1042767e0>, argument=('positional',), kwargs={})]
From print_time 1554204136.855422 keyword From print_time 1554204136.855669 positional 1554204136.855788
---------- nosy: +giampaolo.rodola, xtreak _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue34677> _______________________________________
Cheryl Sabella <cheryl.sabella@gmail.com> added the comment: Thank you for the report. As others have said, the actual time.time() value for the two `s.enter` events is different even though the `delay` value of 5 seems like it should be the same. As @xtreak pointed out, the example is clever in showing that using `enter` instead of `enterabs` can make the queue behave in unexpected ways. Closing as 'not a bug'. ---------- nosy: +cheryl.sabella resolution: -> not a bug stage: patch review -> resolved status: open -> closed _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue34677> _______________________________________
participants (4)
-
Cheryl Sabella
-
Karthikeyan Singaravelan
-
mediator42
-
Roundup Robot