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

Use PySerial locking so the serial port isn't used by other programs (ESPTOOL-792) #946

Closed
redfast00 opened this issue Jan 11, 2024 · 2 comments

Comments

@redfast00
Copy link

Is your feature request related to a problem?

I'm always frustrated when I try to flash a chip using esptool, and I accidentally left a serial console open somewhere else, causing esptool to behave weirdly (since multiple programs are using the same serial port, some of the data on the serial port ends up in esptool and the other part end up in the serial console).

Describe the solution you'd like

This can be avoided by advisory locking the serial port; in pyserial, this can be done with pyserial/pyserial#206. A lot of programs already do this, but since this is advisory locking, it only helps if all programs you're using check the lock. See also https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=734086

A one-line fix would be to add under this line https://github.com/espressif/esptool/blob/master/esptool/loader.py#L303 self._port.exclusive = True. If you want to do something fancier, you can also catch the error, and maybe even display the program that is using it. For me, just seeing 'this port is already in use by another program' would already be useful.

Describe alternatives you've considered

No response

Additional context

This is on Linux; I don't think locking in pyserial is implemented in Windows, so it should not cause any issues there.

@github-actions github-actions bot changed the title Use PySerial locking so the serial port isn't used by other programs Use PySerial locking so the serial port isn't used by other programs (ESPTOOL-792) Jan 11, 2024
@dobairoland
Copy link
Collaborator

Thank you for letting us know about this.

@redfast00
Copy link
Author

Thanks for implementing it :)

peterdragun added a commit to peterdragun/esptool that referenced this issue Jul 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants