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.

Author xtreak
Recipients docs@python, giampaolo.rodola, mediator42, xtreak
Date 2019-04-02.11:33:30
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1554204810.63.0.939283845388.issue34677@roundup.psfhosted.org>
In-reply-to
Content
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
History
Date User Action Args
2019-04-02 11:33:30xtreaksetrecipients: + xtreak, giampaolo.rodola, docs@python, mediator42
2019-04-02 11:33:30xtreaksetmessageid: <1554204810.63.0.939283845388.issue34677@roundup.psfhosted.org>
2019-04-02 11:33:30xtreaklinkissue34677 messages
2019-04-02 11:33:30xtreakcreate