Proc Process Management

The proc system is unlike other process management systems. It is inspired by the process systems found in Julia and allows for functions to be completely farmed out to async executions. The proc processes are not forked but are fresh python executions. These new processes will execute many async python functions simultaneously.

When sending a fresh command into a proc process just send in the pop reference and the kwargs, then the function will be started up and the return will be sent back out to the calling function.


Start by adding the proc subsystem to your hub:


Now the proc subsystem is available. Create a new process pool:

await hub.proc.init.pool(3, 'Workers', sock_dir='/tmp')

You now have a worker pool named Workers with 3 processes and the unix sockets for communication will be placed in the /tmp directory.

Before sending function calls to the pool add a new subsystem to the workers. Remember that these processes are not forks, they need to have the subsystems loaded!

Just call with the name of the pool as the first argument followed by the arguments to pop.sub.add. Lets add the actor system so we can get a nice battery of functions to call:

await'Workers', '')

The pool can now be sent functions to be run and awaited for. The functions can be either async functions or just plain python functions. But the real power of the system is found in sending in async functions.

ret = await'Workers', '')

Any args or kwargs passed after the first 2 arguments to will be passed to the called function.


Generators and async generators are also supported, but you need to call a different function with to return a generator. The function to call is

Calling this function will always return an async generator, even if the function called in the proc process is a classic generator, so remember to async for, not just for:

async for ind in'Workers', 'act.test.iterate'):

Tracking Calls

Lets say you want the same worker function to be called repeatedly, perhaps you have a long running async task running that you want to communicate with by calling more functions. Proc can return the staged coroutine and index of the intended process to run on!

ind, coro = await'Workers', '')
await coro

Now you can send another function in that you know will be run on the same process as the previous call:

ret = await'Workers', 1, '')

Async Callback Server

Sometimes it may be required to call a function that will return multiple times. This can be done using a callback function.