alphatwirl.loop.MPEventLoopRunner

class alphatwirl.loop.MPEventLoopRunner(communicationChannel)[source]

This class (concurrently) runs instances of EventLoop.

An instance of this class needs to be initialized with a communication channel with workers that actually run the EventLoop:

runner = MPEventLoopRunner(communicationChannel)

An example of a communication channel is an instance of CommunicationChannel.

The method begin() does nothing in the current version:

runner.begin()

In older versions, multiple processes are forked in this method.

Then, you can give an EventLoop with the method run():

runner.run(eventLoop1)

This class will send the EventLoop to a worker through the communication channel. The worker, then, runs the EventLoop.

You can call the method run() mutiple times:

runner.run(eventLoop2)
runner.run(eventLoop3)
runner.run(eventLoop4)

If workers are in the background, this method immediately returns. Worker are concurrently running the event loops in the background. If the worker is in the foreground, this method won’t return until the worker finishes running the event loop. Whether workers are in the background or foreground depends on the communication channel with which this class is initialized.

After giving all event loops that you need to run to this class, you need to call the method end():

results = runner.end()

If workers are in the background, this method will wait until workers finish running all event loops. If the worker is in the foreground, this method immediately returns. This method returns the results, the list of the values eventLoops return, sorted in the order given with run().

__init__(communicationChannel)[source]

Initialize self. See help(type(self)) for accurate signature.

Methods

__init__(communicationChannel) Initialize self.
begin() does nothing.
end() wait until all event loops end and returns the results.
poll() Return pairs of run ids and results of finish event loops.
receive() Return pairs of run ids and results.
receive_one() Return a pair of a run id and a result.
run(eventLoop) run the event loop in the background.
run_multiple(eventLoops) run the event loops in the background.