Browse Source

Code für Teil21 Interrupts

master
Olli Graf 10 months ago
parent
commit
278d79f6d0
  1. 2
      teil20/bin/pip
  2. 2
      teil20/bin/pip3
  3. 2
      teil20/bin/wheel
  4. 19
      teil21/alarm.py
  5. 41
      teil21/interrupts.py

2
teil20/bin/pip

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

2
teil20/bin/pip3

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

2
teil20/bin/wheel

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

19
teil21/alarm.py

@ -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

@ -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')
Loading…
Cancel
Save