astro-pi / python-sense-emu

An emulator for the Raspberry Pi Sense HAT
https://sense-emu.readthedocs.io/
Other
40 stars 25 forks source link

Ctrl + C kills spawned GUI when launched from shell #22

Closed bennuttall closed 6 years ago

bennuttall commented 7 years ago

When the GUI is automatically spawned from a Python shell, any keyboard interrupt will silently kill the GUI.

To reproduce:

  1. Open a Python shell

  2. Import sense_emu and create a SenseHat object:

    from sense_emu import SenseHat
    sense = SenseHat()

    (A GUI will be spawned automatically)

  3. Run a while loop, e.g:

    while True:
        print(1)
  4. Hit Ctrl + C to terminate the loop

  5. Try to update the Sense Hat display:

    sense.clear(255, 0, 0)

    (the LEDs on the display should go red, but they don't)

  6. Re-initialise the GUI:

    sense = SenseHat()

    (note the leds are now red)

  7. Try to update the display again:

    sense.clear()

    (this should (and does) clear the leds)

It seems that killing the while loop also kills the GUI process spawned from the shell.

waveform80 commented 6 years ago

This is because signals are sent to the process group on Linux/UNIX (and Windows? Not sure). Easy enough to fix with setpgrp - I'll push something in a mo.