-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSignalHandle.py
More file actions
41 lines (30 loc) · 914 Bytes
/
SignalHandle.py
File metadata and controls
41 lines (30 loc) · 914 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# -*- coding: utf-8 -*-
"""
Created on Mon Jun 8 14:44:46 2020
@author: Jin Dou
"""
import signal
import sys
class CFkeyboardInterrupt:
def __init__(self):
self._register = set()
def __call__(self,func):
if(callable(func)):
self._register.add(func)
else:
raise ValueError("input should be a function")
def handler(self,signalInput,frame):
for func in self._register:
err,errmsg = func(signalInput,frame)
if(err == False):
print(errmsg)
return
sys.exit(0)
def test_signal_handler(self,signal,frame):
print('You pressed Ctrl+C!')
fKeyboardInterruptRegistrar = CFkeyboardInterrupt()
signal.signal(signal.SIGINT,fKeyboardInterruptRegistrar.handler)
#print('Press Ctrl+C')
#for x in range(1,100):
# time.sleep(2)
# print(x)