Eidolon
Public Member Functions | Static Public Member Functions | Public Attributes | Static Public Attributes | List of all members
ProcessServer Class Reference

Inherits Thread.

Collaboration diagram for ProcessServer:
Collaboration graph

Public Member Functions

def __init__ (self, realnumprocs=cpu_count())
 
def callProcessFunc (self, valrange, numprocs, task, target, args, kwargs)
 
def prepareArgs (self, index, numprocs, args, partArgs)
 
def run (self)
 
def stop (self)
 

Static Public Member Functions

def createGlobalServer (realnumprocs=cpu_count())
 

Public Attributes

 daemon
 
 realnumprocs
 
 procs
 
 sharer
 
 syncEvent
 
 syncEvent2
 
 syncCounter
 
 syncLock
 
 jobqueue
 
 progress
 
 objsrv
 
 stopEvent
 

Static Public Attributes

 globalServer = None
 

Detailed Description

This type manages the creation of subprocesses and the despatch of computational tasks to them. Typically the global
instance is created at startup through createGlobalServer() at which point the subprocesses are created. Tasks are
enqueued to be executed through callProcessFunc() or indirectly if a routine decorated with @concurrent is called.

Constructor & Destructor Documentation

◆ __init__()

def __init__ (   self,
  realnumprocs = cpu_count() 
)

Member Function Documentation

◆ callProcessFunc()

def callProcessFunc (   self,
  valrange,
  numprocs,
  task,
  target,
  args,
  kwargs 
)
Sends the request to execute `target' in parallel with the given `args' and `kwargs' argument values. The 
`valrange' value is used to set the value range members of the AlgorithmProcess objects, `numprocs' is the 
number of processes to execute `target' on (1 will cause `target' to be executed in the main process, a value 
<=0 will mean all the processes will be used), and `task' is the (possibly None) Task object to report 
progress to. The return value is a Future object which will contain the results or exceptions thrown.

The `target' routine must exist in a module scope at runtime so inner routines or dynamically created routines
cannot be used here. When called, the first argument will be the AlgorithmProcess object followed by those in
`args' and `kwargs'. The AlgorithmProcess instance will be different for each process `target' is called in,
its members will state which process and the subset of `valrange' assigned to it. The expectation is that
`valrange' is the number of elements `target' is used to operate on, when called each process is assigned a 
subset of the range [0,`valrange') and the internal algorithm of `target' is expected to iterate over those 
values only. 

The optional argument "partitionArgs" in `kwargs' may contain a tuple containing the members in `args' which
are iterable and which should be partitioned amongst the processes. Values in `args' and `kwargs' are normally
copied to each process, so this allows large iterables to be partitioned and not needlessly duplicated.

The @concurrent can be used to wrap the invocation of callProcessFunc() within the function definition itself.
The first argument of the routine must still be the AlgorithmProcess object but when called three arguments
representing `valrange', `numprocs', and `task' must be provided instead. The routine will also no block until
the processing is complete and return the results instead of a Future object.

Example:
    def testfunc(process):
return (process.index,int(process.startval),int(process.endval))
    
    result=ProcessServer.globalServer.callProcessFunc(50,4,None,testfunc)
    printFlush(listResults(result()))

Output: [(0, 0, 12), (1, 12, 25), (2, 25, 37), (3, 37, 50)]

Example:
    @concurrent 
    def testfunc(process,values):
return (process.index,values)
    
    values=range(20)
    result=testfunc(len(values),3,None,values,partitionArgs=(values,))
    printFlush(listResults(result))
    
Output: [(0, [0, 1, 2]), (1, [3, 4, 5]), (2, [6, 7, 8, 9])]

◆ createGlobalServer()

def createGlobalServer (   realnumprocs = cpu_count())
static
Creates the global instance of the server, `realnumprocs' being the number of processes to create.

◆ prepareArgs()

def prepareArgs (   self,
  index,
  numprocs,
  args,
  partArgs 
)
Prepare arguments by dividing lists/tuples present in both `args' and `partArgs' into the slice for proc `index'.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ run()

def run (   self)
Run the server, reading messages from the job queue and sending them to the work processes.
Here is the call graph for this function:

◆ stop()

def stop (   self)
Stops the processes and object server, no execution after this is possible.
Here is the caller graph for this function:

Member Data Documentation

◆ daemon

daemon

◆ globalServer

globalServer = None
static

◆ jobqueue

jobqueue

◆ objsrv

objsrv

◆ procs

procs

◆ progress

progress

◆ realnumprocs

realnumprocs

◆ sharer

sharer

◆ stopEvent

stopEvent

◆ syncCounter

syncCounter

◆ syncEvent

syncEvent

◆ syncEvent2

syncEvent2

◆ syncLock

syncLock

The documentation for this class was generated from the following file: