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

shutdown issue (RuntimeError: must be called from async context) #4

Closed
jsiverskog opened this issue Apr 27, 2021 · 5 comments
Closed

Comments

@jsiverskog
Copy link
Contributor

jsiverskog commented Apr 27, 2021

hi,
if i ctrl-c my program when trio-serial is enabled i get:

Exception ignored in: <function AbstractSerialStream.__del__ at 0x7f1c01048280>
Traceback (most recent call last):
  File "env/lib/python3.9/site-packages/trio_serial/abstract.py", line 146, in __del__
    self.close()
  File "env/lib/python3.9/site-packages/trio_serial/posix.py", line 98, in close
    trio.lowlevel.notify_closing(fd)
  File "env/factory-tencho-env/lib/python3.9/site-packages/trio/_core/_generated_io_epoll.py", line 32, in notify_closing
    raise RuntimeError("must be called from async context")
RuntimeError: must be called from async context

when reading up a bit on this it seems like you're not supposed to do such calls from __del__ (python-trio/trio-asyncio#44), but i'm not sure what the correct solution would look like.

i instantiate my port with:

        self._serial = SerialStream(self._port, exclusive=True,
                                    baudrate=baudrate, rtscts=rtscts)
        await self._serial.aopen()

and doesn't really do much more with it (yet).

any suggestion?

@joernheissler
Copy link
Owner

Hello, thanks for the report.

Minimal code:

#!/usr/bin/env python3

from trio import run
from trio_serial import SerialStream

serial = SerialStream("/dev/ttyS0")
run(serial.aopen)

https://github.com/python-trio/trio/blob/master/trio/_unix_pipes.py#L52-L74 is how trio solved this issue.

Does #5 work for you?

@jsiverskog
Copy link
Contributor Author

what's the easiest way to run this project in "development/editable" mode? with setup.py you can always do python setup.py develop but google hasn't been helpful providing a solution for pyproject.toml.

@jsiverskog
Copy link
Contributor Author

or, how can i just build the package to try it out?

@joernheissler
Copy link
Owner

/path/to/venv/bin/pip install -U .

Or you can install poetry and then run poetry build -f wheel and install the .whl with pip.

@jsiverskog
Copy link
Contributor Author

simple :)

thanks.

i can confirm #5 fixes the issue!

super!

joernheissler added a commit that referenced this issue May 15, 2021
Run trio.lowlevel.notify_closing only from aclose. Fixes #4
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