monome / druid

terminal interface for crow
GNU General Public License v3.0
35 stars 16 forks source link

fix shutdown exceptions (?) by not waiting for canceled task #56

Closed csboling closed 5 years ago

csboling commented 5 years ago

Just doesn't run_until_complete the background task after it has been cancelled, since I think this is all the CancelledError means. @simonvanderveldt this feels almost too easy to be the "right" way to fix #12? Works on Windows and OSX, no hanging shell, no lingering Python processes.

The if is_connected check is just to prevent a traceback if you quit out of druid without having connected a device, because in that case the crow global is None.

simonvanderveldt commented 5 years ago

Yeah, this is the part that's causing the exception, but I'm not sure the .cancel() call makes sense here. Shouldn't the printer keep running so we keep reading from the serial port?

csboling commented 5 years ago

If the prompt-toolkit Application already exited then there's nowhere to show it though, right? Not sure how else to end the background task since read() faulting will just attempt to reconnect.

trentgill commented 5 years ago

This is great. All seems to be working well & fixes the error on Windows (didn't check osx yet).

To be clear, I had no idea what i was doing with the asyncio stuff. I just hacked different examples together until it worked. read: that .cancel call was copied directly from an example and i have no idea what it does.

simonvanderveldt commented 5 years ago

If the prompt-toolkit Application already exited then there's nowhere to show it though, right? Not sure how else to end the background task since read() faulting will just attempt to reconnect.

ah, yeah, you're right, I'm not sure this is the correct way of doing things (ie run run_until_complete followed by a cancel for something else), but it seems to work fine.