Alle Dateien aus dem Pythonkurs
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

42 lines
957 B

#! /usr/bin/python3
import time
import signal
import sys
#Behandlung von SIGINT (CTRL-C)
def handle_sigint(signum, frame) :
print(f'Handling signal {signum} ({signal.Signals(signum).name}).')
if signum == signal.SIGINT:
print(f'SIGINT wird behandelt. {frame}')
time.sleep(1)
sys.exit(0)
#Behandlung von SIGTSTP (CTRL-Z)
def handle_sigtstp(signum,frame):
print(f'Behandle signal {signum} ({signal.Signals(signum).name}).')
print('Programm in Hintergrund')
# Behandlung von SiGCONT
def handle_sigcont(signum,frame):
print(f'Behandle signal {signum} ({signal.Signals(signum).name}).')
print('Programm im Vordergrund')
if __name__ == '__main__':
# Interrupt Handler registrieren
signal.signal(signal.SIGINT, handle_sigint)
signal.signal(signal.SIGTSTP, handle_sigtstp)
signal.signal(signal.SIGCONT, handle_sigcont)
for i in range(0,10000000):
print(f'Schleife: {i}')
time.sleep(0.5)
print('Schleifenende')