I’ve got a jython class, which runs as a thread. I want its run method to create a java Timer, and then schedule one of my class’s functions:
class IBTHXHandler(threading.Thread):
def __init__(self):
threading.Thread.__init__(self, name='IBTHX Handler Thread')
self.start()
def run(self):
print 'ibthx thread running'
timer = Timer
timer.schedule(self.getRealtimeData(), 0, 1000)
def getRealtimeData(self):
print 'Getting Realtime Data'
When I run this code I get this error:
TypeError: schedule(): 1st arg can't be coerced to java.util.TimerTask
I’ve also tried
timer.schedule(self.getRealtimeData, 0, 1000)
Which gives me
TypeError: schedule(): self arg can't be coerced to java.util.Timer
Is there a better way to approach this rather than using a Java Timer?
I looked at using the python threading.Timer class, but that gave me problems (I think because I was calling it from within another thread??)
Anyway, thanks for looking at this.
There are two problems with the code. The first is that you forgot the () after Timer to instantiate it, and the second is that the first arg to schedule must be a timer task. The following code should work. Hope this helps!