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

pyzeebe 2.4.0 to 3.0.0 Trouble #239

Open
seb-835 opened this issue Oct 28, 2021 · 9 comments
Open

pyzeebe 2.4.0 to 3.0.0 Trouble #239

seb-835 opened this issue Oct 28, 2021 · 9 comments
Labels
documentation Improvements or additions to documentation

Comments

@seb-835
Copy link

seb-835 commented Oct 28, 2021

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 ?

@kbakk
Copy link
Collaborator

kbakk commented Oct 28, 2021

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

@seb-835
Copy link
Author

seb-835 commented Oct 29, 2021

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.

@kbakk
Copy link
Collaborator

kbakk commented Oct 29, 2021

@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.

@Andy-JB
Copy link
Contributor

Andy-JB commented Oct 30, 2021

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()

@seb-835
Copy link
Author

seb-835 commented Nov 2, 2021

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,

@kbakk
Copy link
Collaborator

kbakk commented Nov 2, 2021

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.

@seb-835
Copy link
Author

seb-835 commented Nov 5, 2021

@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

@JonatanMartens
Copy link
Collaborator

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

@Janiot
Copy link

Janiot commented Mar 2, 2022

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.

@dimastbk dimastbk added the documentation Improvements or additions to documentation label Jun 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

6 participants