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

Enable using existing asyncio loop #326

Closed
dhoomakethu opened this issue Sep 7, 2018 · 1 comment
Closed

Enable using existing asyncio loop #326

dhoomakethu opened this issue Sep 7, 2018 · 1 comment

Comments

@dhoomakethu
Copy link
Contributor

Versions

  • Python:
  • OS:
  • Pymodbus: dev branch
  • Modbus Hardware (if used): N/A

Pymodbus Specific

  • Client: tcp/rtu/ascii -async

Description

Reported by @makuser in #246 (comment)

TBH I'm not quite sure how to implement this, since I'm using already using my own asyncio loop in my application.

Since It's using loop.run_until_complete in pymodbus/client/async/factory/tcp.py#L97, it would start a new loop on its own, which is not desirable and leads to a Runtime Exception. IMO it should give the option to attach to a loop that's already running.

Code and Logs

 Task exception was never retrieved
future: <Task finished coro=<BAS.async_start() done, defined at /srv/bas/lib/python3.5/site-packages/bas/core.py:70> exception=RuntimeError('This event loop is already running',)>
Traceback (most recent call last):
  File "/usr/lib/python3.5/asyncio/tasks.py", line 239, in _step
    result = coro.send(None)
  File "/srv/bas/lib/python3.5/site-packages/bas/core.py", line 72, in async_start
    await neuron.switch_to_async(self.loop, self.basConfig.alias_dict)
  File "/srv/bas/lib/python3.5/site-packages/bas/brain.py", line 141, in createClient
    loopi, clienti = ModbusClient(schedulers.ASYNC_IO, host=self.modbus_server, port=self.modbus_port, loop=self.loop)
  File "/srv/bas/lib/python3.5/site-packages/pymodbus/client/async/tcp.py", line 45, in __new__
    timeout=timeout, **kwargs)
  File "/srv/bas/lib/python3.5/site-packages/pymodbus/client/async/factory/tcp.py", line 97, in async_io_factory
    client = loop.run_until_complete(asyncio.gather(cor))[0]
  File "/usr/lib/python3.5/asyncio/base_events.py", line 454, in run_until_complete
    self.run_forever()
  File "/usr/lib/python3.5/asyncio/base_events.py", line 408, in run_forever
    raise RuntimeError('This event loop is already running')
RuntimeError: This event loop is already running

@dhoomakethu dhoomakethu added this to the 2.0.0 milestone Sep 7, 2018
@dhoomakethu
Copy link
Contributor Author

dhoomakethu commented Sep 7, 2018

Workarounds :
#246 (comment)

Suggestions:
#246 (comment)

dhoomakethu added a commit that referenced this issue Sep 7, 2018
2. Add to_coils() method to BinaryPayloadBuildr
dhoomakethu added a commit that referenced this issue Sep 21, 2018
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 21, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

1 participant