pyzeebe icon indicating copy to clipboard operation
pyzeebe copied to clipboard

pyzeebe 2.4.0 to 3.0.0 Trouble

Open seb-835 opened this issue 4 years ago • 9 comments

Hi, i got a worker running in pyzeebe 2.4.0, i made the change to have it using pyzeebe 3.0.0 In my code, i replace :

worker = ZeebeWorker(hostname=gateway.hostname, port=gateway.port, secure_connection=scheme )

by

channel = create_insecure_channel(hostname=gateway.hostname, port=gateway.port)
worker = ZeebeWorker(channel)

and i replace

worker.work() 

by

loop = asyncio.get_running_loop()
loop.run_until_complete(worker.work())

But, the worker failed with error : no running event loop what do i missed ?

seb-835 avatar Oct 28 '21 12:10 seb-835

@seb-835 Can you post the full stack trace / output with the error? Also, what version of Python are you running?

kbakk avatar Oct 28 '21 14:10 kbakk

Hi, i try with python 3.7, 3.8. 3.10 from docker image python:3.7 3.8 3.10 . The traceback is very short :

File "/src/worker.py", line 55, in loop = asyncio.get_running_loop() RuntimeError: no running event loop

i can make a pastebin of the code, there is no secret in.

seb-835 avatar Oct 29 '21 06:10 seb-835

@seb-835 Hmm, I don't immediatly see the issue. From the error, it could be something related to what's reported here: https://stackoverflow.com/questions/58774718/asyncio-in-corroutine-runtimeerror-no-running-event-loop

But I don't see how that translates to Pyzeebe.

If you follow the quickstart, does that work?

It would be most helpful if you can create a minimal reproducer.

kbakk avatar Oct 29 '21 18:10 kbakk

I think I got around this issue by using loop = asyncio.get_event_loop() Or loop = asyncio.new_event_loop() Instead of loop = asyncio.get_running_loop()

Andy-JB avatar Oct 30 '21 01:10 Andy-JB

Many thanks @kbakk @Andy-JB

One of the workaround give by @Andy-JB work,

if i replace loop = asyncio.get_running_loop() by loop = asyncio.get_event_loop() it complains first : DeprecationWarning: There is no current event loop but work.

with loop = asyncio.new_event_loop(), it crash :

RuntimeError: Task <Task pending name='Task-2' coro=<JobPoller.poll() running at /usr/local/lib/python3.10/site-packages/pyzeebe/worker/job_poller.py:28> cb=[gather.<locals>._done_callback() at /usr/local/lib/python3.10/asyncio/tasks.py:718]> got Future <Task pending name='Task-4' coro=<UnaryStreamCall._send_unary_request() running at /usr/local/lib/python3.10/site-packages/grpc/aio/_call.py:557>> attached to a different loop

@kbakk i got a minimal code reproducer if you need,

seb-835 avatar Nov 02 '21 11:11 seb-835

See https://docs.python.org/3/library/asyncio-eventloop.html#asyncio.get_event_loop:

Consider also using the asyncio.run() function instead of using lower level functions to manually create and close an event loop.

See description here for an example of how to use asyncio.run. This is probably what the documentation should use as an example.

Can you test this, @seb-835? Feel free to upload the reproducer here (zip the files) or to a gist, it can be useful for further troubleshooting.

kbakk avatar Nov 02 '21 13:11 kbakk

@kbakk using asyncio.run(worker.work()) make worker crash too

Task <Task pending name='Task-2' coro=<JobPoller.poll() running at /usr/local/lib/python3.10/site-packages/pyzeebe/worker/job_poller.py:28> cb=[gather.<locals>._done_callback() at /usr/local/lib/python3.10/asyncio/tasks.py:718]> got Future <Task pending name='Task-4' coro=<UnaryStreamCall._send_unary_request() running at /usr/local/lib/python3.10/site-packages/grpc/aio/_call.py:557>> attached to a different loop
Traceback (most recent call last):
  File "/src/worker.py", line 55, in <module>
    asyncio.run(worker.work())
  File "/usr/local/lib/python3.10/asyncio/runners.py", line 44, in run
    return loop.run_until_complete(main)
  File "/usr/local/lib/python3.10/asyncio/base_events.py", line 641, in run_until_complete
    return future.result()
  File "/usr/local/lib/python3.10/site-packages/pyzeebe/worker/worker.py", line 91, in work
    await self._work_task
  File "/usr/local/lib/python3.10/site-packages/pyzeebe/worker/job_poller.py", line 28, in poll
    await self.activate_max_jobs()
  File "/usr/local/lib/python3.10/site-packages/pyzeebe/worker/job_poller.py", line 32, in activate_max_jobs
    await self.poll_once()
  File "/usr/local/lib/python3.10/site-packages/pyzeebe/worker/job_poller.py", line 47, in poll_once
    async for job in jobs:
  File "/usr/local/lib/python3.10/site-packages/pyzeebe/grpc_internals/zeebe_job_adapter.py", line 23, in activate_jobs
    async for response in self._gateway_stub.ActivateJobs(
  File "/usr/local/lib/python3.10/site-packages/grpc/aio/_call.py", line 320, in _fetch_stream_responses
    message = await self._read()
  File "/usr/local/lib/python3.10/site-packages/grpc/aio/_call.py", line 336, in _read
    await self._preparation

Here is the reproducer code : https://gist.github.com/seb-835/c495fafe0307927e4ed7cd587fa355a2

seb-835 avatar Nov 05 '21 07:11 seb-835

I've updated the docs to use get_event_loop instead of get_running_loop. This still feels like a workaround to me, so I'm keeping this issue open

JonatanMartens avatar Dec 03 '21 12:12 JonatanMartens

Hello, it would be nice if you cloud also change it in the README.md, I took me quite a while to figure out the problem and to find this issue. Thank you.

Janiot avatar Mar 02 '22 20:03 Janiot