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 kfj
Recipients kfj
Date 2009-04-24.13:35:03
SpamBayes Score 2.3536728e-14
Marked as misclassified No
Message-id <1240580106.04.0.721938894312.issue5830@psf.upfronthosting.co.za>
In-reply-to
Content
scheduler uses heapq to schedule it's events. Heapq uses plain >/< 
comparisons on the events. Now that comparisons of incomparable data 
are no longer valid, the comparison fails if two events are scheduled 
for the same time with the same priority, since the comparison 
continues with comparing the 'action' components ov the event's tuple. 
I suppose this behaviour is unwanted - at least I did not expect it and 
it took me some time to figure out what it was due to. I worked around 
it by assigning comparison functions to the event data type - since 
this is part of the standard library, maybe a general fix should be 
considered? Here's my humble snippet of code:

def evtlt ( self , other ):
	if self.time < other.time:
		return True
	elif self.time == other.time:
		return self.priority < other.priority
	return False

sched.Event.__lt__ = evtlt

def evtgt ( self , other ):
	if self.time > other.time:
		return True
	elif self.time == other.time:
		return self.priority > other.priority
	return False

sched.Event.__gt__ = evtgt

If anyone would care to reproduce the (?)bug, try:

import sched

def foo():
	pass

def bar():
	pass

s = sched.scheduler(None, None) 

s.enterabs ( 0 , 0 , foo , () )
s.enterabs ( 0 , 0 , bar , () )

this produces the following output:

Traceback (most recent call last):
  File "./schedbug.py", line 12, in <module>
    s.enterabs ( 0 , 0 , bar , () )
  File "c:\Programme\Python3.0\lib\sched.py", line 54, in enterabs
    heapq.heappush(self._queue, event)
TypeError: unorderable types: function() < function()
History
Date User Action Args
2009-04-24 13:35:06kfjsetrecipients: + kfj
2009-04-24 13:35:06kfjsetmessageid: <1240580106.04.0.721938894312.issue5830@psf.upfronthosting.co.za>
2009-04-24 13:35:04kfjlinkissue5830 messages
2009-04-24 13:35:03kfjcreate