Black Lives Matter - Action and Equality. ... Adafruit is open and shipping.
0

context manager fails when interrupting input()
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

context manager fails when interrupting input()

by bludin on Fri Jun 12, 2020 5:48 am

The context manager __exit__() of an object is not called when I control-c an input() statement but it works when I control-c any other code within the same context (i.e. with-block for that object). How can I fix that?

bludin
 
Posts: 20
Joined: Thu Apr 16, 2020 8:57 am

Re: context manager fails when interrupting input()

by tannewt on Fri Jun 12, 2020 11:56 am

Sounds like a bug! Please file an issue here with a test case: https://github.com/adafruit/circuitpython/issues/new

tannewt
 
Posts: 1685
Joined: Thu Oct 06, 2016 8:48 pm

Re: context manager fails when interrupting input()

by bludin on Sat Jun 13, 2020 5:42 am

I'll do so. I just have to dig a little deeper, because I found that I've been too sloppy.

ctrl-c only takes effect at the input prompt after hitting return. In that case, __exit__() is called as it should. Where it fails is if I hit ctrl-d at the input prompt (only effective when hit before typing anything else). In that case, the program exits without __exit__() being called.

bludin
 
Posts: 20
Joined: Thu Apr 16, 2020 8:57 am

Please be positive and constructive with your questions and comments.