2 Commits

Author SHA1 Message Date
ec60c85695 Readme updated 2023-12-11 07:50:37 +01:00
278d79f6d0 Code für Teil21 Interrupts 2023-12-11 07:49:21 +01:00
6 changed files with 64 additions and 3 deletions

View File

@@ -25,4 +25,5 @@ CC-BY-SA Olli Graf
|18 | Generatoren und list comprehension|
|19 | Webseiten (Flask)|
|20 | virtuelle Umgebungen|
|21 | Interrupts & Signale|

View File

@@ -1,4 +1,4 @@
#!/home/pi/git/pythonkurs/teil20/bin/python
#!/home/pi/git/pythonkurs/teil20/bin/python3
# -*- coding: utf-8 -*-
import re
import sys

View File

@@ -1,4 +1,4 @@
#!/home/pi/git/pythonkurs/teil20/bin/python
#!/home/pi/git/pythonkurs/teil20/bin/python3
# -*- coding: utf-8 -*-
import re
import sys

View File

@@ -1,4 +1,4 @@
#!/home/pi/git/pythonkurs/teil20/bin/python
#!/home/pi/git/pythonkurs/teil20/bin/python3
# -*- coding: utf-8 -*-
import re
import sys

19
teil21/alarm.py Executable file
View File

@@ -0,0 +1,19 @@
#! /usr/bin/python3
# encoding:utf-8
import signal
import time
def handle_alarm(signum, frame):
print(f'Alarm ausgelöst bei {time.ctime()}')
signal.signal(signal.SIGALRM,handle_alarm)
signal.alarm(3)
print(f'aktuelle Zeit Start: {time.ctime()}')
time.sleep(13)
print(f'aktuelle Zeit Ende: {time.ctime()}')

41
teil21/interrupts.py Executable file
View File

@@ -0,0 +1,41 @@
#! /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')