Skip to content

0.2.7

Latest
Compare
Choose a tag to compare
@Nanguage Nanguage released this 28 Sep 14:27

Support the send method for the generator, this feature can be used for pass data to the generator, it allow executor communicate with another thread/process:

import asyncio
from executor.engine import Engine, ProcessJob

def calculator():
    res = None
    while True:
        expr = yield res
        res = eval(expr)


async def main():
    with Engine() as engine:
        job = ProcessJob(calculator)
        await engine.submit_async(job)
        await job.wait_until_status("running")
        g = job.result()
        g.send(None)  # initialize the generator
        print(g.send("1 + 2"))  # 3
        print(g.send("3 * 4"))  # 12
        print(g.send("(1 + 2) * 4"))  # 12

asyncio.run(main())

Full Changelog: 0.2.6...0.2.7