C
codecraig
If i have a class such as
class Foo:
def doSomething(self, cmd, cmd2, callback):
cmd = <translate command>
results = <..do some possibly long task..>
callback(results)
What I am looking to do is have that "long task" done in a separate
thread...how can I do this?
I was thinking..
class MyThread(Thread):
def __init__(self, cmd, cmd2, callback):
self.__cmd = cmd
self.__cmd2 = cmd2
self.__callback = callback
def run(self):
# do stuff here
self.__callback(some_results)
....anyhow, this just didnt seem good. I felt like i either had to pass
MyThread a bunch of arguments it needed to run the long task, or i
would end up passing it a 'master'...but then in MyThread I'd have
self.__master.__service.execute_cmd(self.__cmd)
....in java I would just create an inner class..but i am not sure
how/what to do in python.
thanks.
class Foo:
def doSomething(self, cmd, cmd2, callback):
cmd = <translate command>
results = <..do some possibly long task..>
callback(results)
What I am looking to do is have that "long task" done in a separate
thread...how can I do this?
I was thinking..
class MyThread(Thread):
def __init__(self, cmd, cmd2, callback):
self.__cmd = cmd
self.__cmd2 = cmd2
self.__callback = callback
def run(self):
# do stuff here
self.__callback(some_results)
....anyhow, this just didnt seem good. I felt like i either had to pass
MyThread a bunch of arguments it needed to run the long task, or i
would end up passing it a 'master'...but then in MyThread I'd have
self.__master.__service.execute_cmd(self.__cmd)
....in java I would just create an inner class..but i am not sure
how/what to do in python.
thanks.