Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't get the example Pool code to work #183

Open
Deville-ee opened this issue Feb 22, 2023 · 1 comment
Open

Can't get the example Pool code to work #183

Deville-ee opened this issue Feb 22, 2023 · 1 comment

Comments

@Deville-ee
Copy link

Deville-ee commented Feb 22, 2023

Description

I can't execute the example code in the Process section. Both the apply() method as the map(math.sqrt) method.

Documentation

I've managed to get the math.sqrt working but not like indicated in the example. I moved the math.sqrt call to an asyncio aware section because if I don't, the interpreter complains about exactly this.

TypeError: An asyncio.Future, a coroutine or an awaitable is required

Edit: To be complete : I'm getting following error when using the apply() method:

RuntimeError: await wasn't used with future

_
My adaptation for the sqrt example:

import asyncio
import math
from aiomultiprocess import Pool


async def sqrt_task(data):
    return math.sqrt(data)


async def main():
    async with Pool() as pool:
        data = [1, 4, 9, 16, 25]
        results = await pool.map(sqrt_task, data)
        print(results)


if __name__ == '__main__':
    asyncio.run(main())

Details

  • OS: Ubuntu 22.04.1 LTS
  • Python version: 3.7.10
  • aiomultiprocess version: 0.9.0
  • Can you repro on master?
  • Can you repro in a clean virtualenv?
@wbarnha
Copy link

wbarnha commented Aug 12, 2023

You may want to take a look at https://stackoverflow.com/questions/64429359/how-to-use-aiomultiprocess. Reapplying the example provided, you should be able to run this:

import asyncio
import math
from aiomultiprocess import Pool


async def sqrt_task(data):
    return math.sqrt(data)


async def main():
    async with Pool() as pool:
        data = [1, 4, 9, 16, 25]
        async for result in pool.map(sqrt_task, data):
           print(result)


if __name__ == '__main__':
    asyncio.run(main())

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants