Skip to content
This repository was archived by the owner on May 18, 2023. It is now read-only.
This repository was archived by the owner on May 18, 2023. It is now read-only.

How got celery task result? #30

@kimeuichan

Description

@kimeuichan
  • Celery Executor version: celery[redis]==4.3.1
  • Python version:Python 3.7
  • Operating System:macOS mojave

Description

I want to using this library in Sanic for asyncio.

I used redis result backend like this.

app = Celery("task", broker="amqp://guest:guest@localhost", backend="redis://localhost:6379/0")

My celery task.py

@app.task(name="test")
async def my_task():
    print("HERE")
    await asyncio.sleep(5)
    print("HERE")

    return "HERE"


async def main():
    async_result = await my_task.delay()
    return await async_result.get()


if __name__ == '__main__':
    loop = asyncio.get_event_loop()
    print(loop.run_until_complete(main()))

but It's raise TypeError like this.

Traceback (most recent call last):
  File "<input>", line 1, in <module>
  File "/Applications/PyCharm.app/Contents/plugins/python/helpers/pydev/_pydev_bundle/pydev_umd.py", line 197, in runfile
    pydev_imports.execfile(filename, global_vars, local_vars)  # execute the script
  File "/Applications/PyCharm.app/Contents/plugins/python/helpers/pydev/_pydev_imps/_pydev_execfile.py", line 18, in execfile
    exec(compile(contents+"\n", file, 'exec'), glob, loc)
  File "/Users/<project>/core/task.py", line 30, in <module>
    print(loop.run_until_complete(main()))
  File "/Users/gim-uichan/.pyenv/versions/3.7.1/lib/python3.7/asyncio/base_events.py", line 573, in run_until_complete
    return future.result()
  File "/Users/<project>/core/task.py", line 25, in main
    return await async_result.get()
  File "/Users/<project>/worker-venv/lib/python3.7/site-packages/celery_pool_asyncio/asynchronous.py", line 33, in wait_for_pending
    async for _ in self._wait_for_pending(result, **kwargs):
  File "/Users/<project>/worker-venv/lib/python3.7/site-packages/celery_pool_asyncio/asynchronous.py", line 17, in _wait_for_pending
    on_interval=on_interval):
  File "/Users/<project>/worker-venv/lib/python3.7/site-packages/celery_pool_asyncio/asynchronous.py", line 42, in drain_events_until
    on_interval=on_interval,
  File "/Users/<project>/worker-venv/lib/python3.7/site-packages/celery_pool_asyncio/drainer.py", line 23, in drain_events_until
    yield await self.wait_for(p, wait, timeout=1)
  File "/Users/<project>/worker-venv/lib/python3.7/site-packages/celery_pool_asyncio/drainer.py", line 32, in wait_for
    async for _ in wait(timeout=timeout):
TypeError: 'async for' requires an object with __aiter__ method, got NoneType

Can I get celery result using this library?

If don't setting celery result backend. It raise NotImplementError like this.

NotImplementedError: No result backend is configured.
Please see the documentation for more information.

I red your example.
but example is not working too..

What I Did

Tell me how do I get celery task result.

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