Add information about signal handler
This commit is contained in:
parent
8fc06a1453
commit
7c3129a1b2
@ -45,3 +45,22 @@ except KeyboardInterrupt:
|
|||||||
# return SIGINT code
|
# return SIGINT code
|
||||||
exit(130)
|
exit(130)
|
||||||
```
|
```
|
||||||
|
|
||||||
|
A potentially better way of handling keyboard interrupts is using a signal handler.
|
||||||
|
|
||||||
|
```python
|
||||||
|
import time
|
||||||
|
import signal
|
||||||
|
import sys
|
||||||
|
|
||||||
|
def signal_handler(signal, frame):
|
||||||
|
print("\nKeyboard Interrupt detected.")
|
||||||
|
# add your cleanup code here
|
||||||
|
sys.exit(0)
|
||||||
|
|
||||||
|
# register signal handler
|
||||||
|
signal.signal(signal.SIGINT, signal_handler)
|
||||||
|
|
||||||
|
while True:
|
||||||
|
time.sleep(1)
|
||||||
|
```
|
||||||
|
Loading…
Reference in New Issue
Block a user