G
Guest
I have a workerclass which takes in several parameters
for initialization. This class would have a doWork
function. Currently this function has a loop which
does all the work and then returns. I have to extend
the application to be able to support many different
workerClass instances all executing at the same time.
I was thinking of using generators to do this.
I have the following questions on generators:
1. Can a generator function be inside a class
2. When you yield a generator, are all the instance
variables of the class saved as well.
3. If I want to do n units of work for each call to
the generator function, how do I pass the n to the
generator function?
class WorkerClass():
def __init__(self, someVariables):
self.someVariables
initializtionFunctionCalls()
def workerFunction(self, numUnitsOfWork):
count = 0
for i in timeUnits:
application logic
if count == numUnitsOfWork:
yield None
<end of function application logic>
I'll then have a thread manager which will initialize
all the worker classes and make calls to
workerfunctions based ont he priority of each worker
class. Will this work?
for initialization. This class would have a doWork
function. Currently this function has a loop which
does all the work and then returns. I have to extend
the application to be able to support many different
workerClass instances all executing at the same time.
I was thinking of using generators to do this.
I have the following questions on generators:
1. Can a generator function be inside a class
2. When you yield a generator, are all the instance
variables of the class saved as well.
3. If I want to do n units of work for each call to
the generator function, how do I pass the n to the
generator function?
class WorkerClass():
def __init__(self, someVariables):
self.someVariables
initializtionFunctionCalls()
def workerFunction(self, numUnitsOfWork):
count = 0
for i in timeUnits:
application logic
if count == numUnitsOfWork:
yield None
<end of function application logic>
I'll then have a thread manager which will initialize
all the worker classes and make calls to
workerfunctions based ont he priority of each worker
class. Will this work?