Question on weightless threads and generators:

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?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,756
Messages
2,569,533
Members
45,007
Latest member
OrderFitnessKetoCapsules

Latest Threads

Top