Search code examples
pythonwindowspython-idlepyserial

How to break a command execution in Python?


I was using PySerial when I typed

serialObject.read()

And the execution hanged waiting for some serial data. How to abort this command? I want to type new commands and ignore this one. I'm using IDLE on Windows and Ctrl+C doesn't seem to work.


Solution

  • Configure PySerial to timeout if no data is received before the time limit. If you don't have a timeout, then your only option is to ask the OS to kill the process.