Properly handle serial close on Macs
Properly handle serial close on Macs

Readline could still be stuck in a read loop, leading to an exception on Mac
when closing the connection from another thread. This should now be captured
correctly.

Fixes #1021
(cherry picked from commit c829b27)

mcanes/OctoPrint,dragondgold/OctoPrint,Javierma/OctoPrint-TFG,mcanes/OctoPrint,nickverschoor/OctoPrint,ErikDeBruijn/OctoPrint,foosel/OctoPrint,bicephale/OctoPrint,Salandora/OctoPrint,ErikDeBruijn/OctoPrint,JackGavin13/octoprint-test-not-finished,leductan-nguyen/RaionPi,nickverschoor/OctoPrint,mcanes/OctoPrint,punkkeks/OctoPrint,eliasbakken/OctoPrint,JackGavin13/octoprint-test-not-finished,Skeen/OctoPrint,Jaesin/OctoPrint,foosel/OctoPrint,senttech/OctoPrint,ryanneufeld/OctoPrint,bicephale/OctoPrint,bicephale/OctoPrint,beeverycreative/BEEweb,beeverycreative/BEEweb,shohei/Octoprint,Salandora/OctoPrint,Jaesin/OctoPrint,senttech/OctoPrint,foosel/OctoPrint,punkkeks/OctoPrint,eddieparker/OctoPrint,Jaesin/OctoPrint,dragondgold/OctoPrint,masterhou/OctoPrint,nicanor-romero/OctoPrint,chriskoz/OctoPrint,Javierma/OctoPrint-TFG,senttech/OctoPrint,leductan-nguyen/RaionPi,Jaesin/OctoPrint,nicanor-romero/OctoPrint,Mikk36/OctoPrint,MaxOLydian/OctoPrint,punkkeks/OctoPrint,MaxOLydian/OctoPrint,shohei/Octoprint,beeverycreative/BEEweb,masterhou/OctoPrint,ryanneufeld/OctoPrint,CapnBry/OctoPrint,JackGavin13/octoprint-test-not-finished,eliasbakken/OctoPrint,Mikk36/OctoPrint,dansantee/OctoPrint,Skeen/OctoPrint,CapnBry/OctoPrint,nicanor-romero/OctoPrint,senttech/OctoPrint,Mikk36/OctoPrint,leductan-nguyen/RaionPi,foosel/OctoPrint,MoonshineSG/OctoPrint,eddieparker/OctoPrint,chriskoz/OctoPrint,Javierma/OctoPrint-TFG,leductan-nguyen/RaionPi,dansantee/OctoPrint,MoonshineSG/OctoPrint,MaxOLydian/OctoPrint,shohei/Octoprint,MoonshineSG/OctoPrint,chriskoz/OctoPrint,ryanneufeld/OctoPrint,MoonshineSG/OctoPrint,dansantee/OctoPrint,nickverschoor/OctoPrint,shohei/Octoprint,JackGavin13/octoprint-test-not-finished,Salandora/OctoPrint,Javierma/OctoPrint-TFG,eliasbakken/OctoPrint,ErikDeBruijn/OctoPrint,chriskoz/OctoPrint,dragondgold/OctoPrint,Skeen/OctoPrint,nickverschoor/OctoPrint,CapnBry/OctoPrint,bicephale/OctoPrint,masterhou/OctoPrint,CapnBry/OctoPrint,eddieparker/OctoPrint,Salandora/OctoPrint,shohei/Octoprint,beeverycreative/BEEweb,ryanneufeld/OctoPrint