mirror of
https://github.com/Brandon-Rozek/website.git
synced 2025-10-10 06:51:13 +00:00
[New] Posts on cloc, python interrupts, and zsh&snaps
This commit is contained in:
parent
a44c57f028
commit
d9e8f4aab9
3 changed files with 107 additions and 0 deletions
24
content/blog/pythoninterrupts.md
Normal file
24
content/blog/pythoninterrupts.md
Normal file
|
@ -0,0 +1,24 @@
|
|||
---
|
||||
title: "Quick Python: Interrupts"
|
||||
date: 2020-01-25T09:51:34-05:00
|
||||
draft: false
|
||||
images: []
|
||||
---
|
||||
|
||||
This post is part of a new series I'm starting where I quickly outline small Python snippets.
|
||||
|
||||
If you have an application that you want to gracefully exit when the user presses CTRL-C here's the short snippet
|
||||
```python
|
||||
import signal
|
||||
import sys
|
||||
|
||||
# Function that gets called when interrupt is found
|
||||
def signal_handler(sig, frame):
|
||||
print('You pressed Ctrl+C!')
|
||||
sys.exit(0)
|
||||
|
||||
# Attach the function to the interrupt signal
|
||||
signal.signal(signal.SIGINT,signal_handler)
|
||||
|
||||
print('Press Ctrl+C')
|
||||
```
|
Loading…
Add table
Add a link
Reference in a new issue