这是indexloc提供的服务,不要输入任何密码
Skip to content

Add Exectuors that you can call from synchrone (non asyncio) code. #4

@feluxe

Description

@feluxe

Currently we can use aioexec for asyncio like this:

from aioexec import Procs

aysnc def my_async_func():
    my_values = await asyncio.gather(
        *Procs(3).batch(
            Call(my_func, foo='bar'),
            Call(my_func, foo='baz'),
            Call(my_func, foo='qux'),
        )
    )

It would be nice to use Procs from non-asyncio code as well:

from aioexec.sync import Procs, gather

def my_non_async_func():

    # Call a single function in another process.
    future = Procs(1).call(my_func, foo='baz')
    my_value = future.result()

    # Or in one line:
    result = Procs(1).call(my_func, foo='baz').result()
    
    # Call multiple functions in a pool:
    future = gather(
        *Procs(3).batch(
            Call(my_func, foo='bar'),
            Call(my_func, foo='baz'),
            Call(my_func, foo='qux'),
        )
    )
    results = future.result()

    # Call multiple functions in a pool and returns values as completed:
    future = as_completed(
        *Procs(3).batch(
            Call(my_func, foo='bar'),
            Call(my_func, foo='baz'),
            Call(my_func, foo='qux'),
        )
    )
    results = future.result()
   
   # etc...

    

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions