I have a programming tool for an ESP32 platform and this programming tool should use the esptool
and a task to program the ESP32. This is done by a subprocess:
while(True):
Command = "{}".format(os.getcwd()) + os.path.sep + "esptool.py --port {} --after hard_reset flash_id".format(Port)
print("[DEBUG {}] Run command {}".format(Index, Command))
Proc = subprocess.Popen(Command, shell = True, stdout = subprocess.PIPE)
Output = str()
try:
Output = Proc.communicate(timeout = 10)[0].decode("ascii")
except subprocess.TimeoutExpired:
if(args.debug):
print("[DEBUG {}] Process timeout!".format(Index))
Proc.kill()
# Sometimes the application will stuck here. Use a timeout again to prevent it.
try:
Proc.communicate(timeout = 1)
except subprocess.TimeoutExpired:
pass
# Timeout - jump back and try it again
continue
...
The process is started and a timeout occurs:
[DEBUG 0] Run command ...\app\esptool.py --port COM14 --after hard_reset flash_id
[DEBUG 0] Process timeout!
The application should try the programming process again, but I get SerialException
from the esptool.py
.
serial.serialutil.SerialException: could not open port 'COM14': PermissionError(13, 'Zugriff verweigert', None, 5)
It looks like the process is still alive. But why? How can I fix it? I´m testing the application with Windows 10, but it also should run under Linux. I´m using Python 3.9.5 64-Bit
.