def test_siginterrupt(self): import signal, os, time if not hasattr(signal, 'siginterrupt'): skip('non siginterrupt in signal') signum = signal.SIGUSR1 def readpipe_is_not_interrupted(): # from CPython's test_signal.readpipe_interrupted() r, w = os.pipe() ppid = os.getpid() pid = os.fork() if pid == 0: try: time.sleep(1) os.kill(ppid, signum) time.sleep(1) finally: os._exit(0) else: try: os.close(w) # we expect not to be interrupted. If we are, the # following line raises OSError(EINTR). os.read(r, 1) finally: os.waitpid(pid, 0) os.close(r) # oldhandler = signal.signal(signum, lambda x,y: None) try: signal.siginterrupt(signum, 0) readpipe_is_not_interrupted() readpipe_is_not_interrupted() finally: signal.signal(signum, oldhandler)
def test_siginterrupt(self): import signal, os, time signum = signal.SIGUSR1 def readpipe_is_not_interrupted(): # from CPython's test_signal.readpipe_interrupted() r, w = os.pipe() ppid = os.getpid() pid = os.fork() if pid == 0: try: time.sleep(1) os.kill(ppid, signum) time.sleep(1) finally: os._exit(0) else: try: os.close(w) # we expect not to be interrupted. If we are, the # following line raises OSError(EINTR). os.read(r, 1) finally: os.waitpid(pid, 0) os.close(r) # oldhandler = signal.signal(signum, lambda x,y: None) try: signal.siginterrupt(signum, 0) readpipe_is_not_interrupted() readpipe_is_not_interrupted() finally: signal.signal(signum, oldhandler)
def test_set_wakeup_fd(self): import signal, posix, fcntl def myhandler(signum, frame): pass signal.signal(signal.SIGUSR1, myhandler) # def cannot_read(): try: posix.read(fd_read, 1) except OSError: pass else: raise AssertionError, "os.read(fd_read, 1) succeeded?" # fd_read, fd_write = posix.pipe() flags = fcntl.fcntl(fd_write, fcntl.F_GETFL, 0) flags = flags | posix.O_NONBLOCK fcntl.fcntl(fd_write, fcntl.F_SETFL, flags) flags = fcntl.fcntl(fd_read, fcntl.F_GETFL, 0) flags = flags | posix.O_NONBLOCK fcntl.fcntl(fd_read, fcntl.F_SETFL, flags) # old_wakeup = signal.set_wakeup_fd(fd_write) try: cannot_read() posix.kill(posix.getpid(), signal.SIGUSR1) res = posix.read(fd_read, 1) assert res == '\x00' cannot_read() finally: old_wakeup = signal.set_wakeup_fd(old_wakeup) # signal.signal(signal.SIGUSR1, signal.SIG_DFL)
def launch(self, alive_time = None, enable_gui = True): ''' Launch the threaded application @param alive_time msec for live app, normally used by test. Default None for ignore @param enable_gui launch the program loading the GUI if True ''' if hasattr(self, 'p'): self.p.destroy() del self.p # Cleanup any state set by the FreeStationApp. # import signal #@Reimport #if signal.__dict__.has_key('SIGHUP'): # signal.signal(signal.SIGHUP, signal.SIG_DFL) #if signal.__dict__.has_key('SIGBREAK'): # signal.signal(signal.SIGBREAK, signal.SIG_DFL) #@UndefinedVariable signal.signal(signal.SIGINT, signal.SIG_DFL) signal.signal(signal.SIGTERM, signal.SIG_DFL) import os if os.path.exists('webkit.lock'): os.remove('webkit.lock') self.p = None self.p = FreeStationApp(alive_time, enable_gui) self.p.setName(self.PROCESS_MONITORED_NAME + '-' + str(time())) self.threads.append(self.p) self.p.start()
def new_f(*args, **kwargs): old = signal.signal(signal.SIGALRM, handler) signal.alarm(seconds_before_timeout) try: result = f(*args, **kwargs) finally: signal.signal(signal.SIGALRM, old) signal.alarm(0) return result
def test_itimer_real(self): import signal def sig_alrm(*args): self.called = True signal.signal(signal.SIGALRM, sig_alrm) old = signal.setitimer(signal.ITIMER_REAL, 1.0) assert old == (0, 0) val, interval = signal.getitimer(signal.ITIMER_REAL) assert val <= 1.0 assert interval == 0.0 signal.pause() assert self.called
def timeout(seconds, exception_cls=TimeoutError): if hasattr(signal, "SIGALRM"): def _signal_handler(signum, frame): raise exception_cls("Timeout after {seconds} seconds.") signal.signal(signal.SIGALRM, _signal_handler) signal.alarm(seconds) try: yield finally: signal.alarm(0) else: timer = threading.Timer(seconds, lambda: _thread.interrupt_main()) timer.start() try: yield except KeyboardInterrupt: raise exception_cls(f"Timeout after {seconds} seconds.") finally: timer.cancel()
def launch(self, alive_time = None, enable_gui = True): ''' Launch the threaded application @param alive_time msec for live app, normally used by test. Default None for ignore @param enable_gui launch the program loading the GUI if True ''' if hasattr(self, 'p'): self.p.destroy() del self.p # Cleanup any state set by the FreeStationApp. # import signal if signal.__dict__.has_key('SIGHUP'): signal.signal(signal.SIGHUP, signal.SIG_DFL) if signal.__dict__.has_key('SIGBREAK'): signal.signal(signal.SIGBREAK, signal.SIG_DFL) #@UndefinedVariable signal.signal(signal.SIGINT, signal.SIG_DFL) signal.signal(signal.SIGTERM, signal.SIG_DFL) import os if os.path.exists('webkit.lock'): os.remove('webkit.lock') GObject.threads_init() Gdk.threads_init() newpid = os.fork() self.children_pid = newpid if newpid == 0: # Child print 'Child' self.p = None self.p = FreeStationApp2(alive_time, enable_gui) #self.p.setName(self.PROCESS_MONITORED_NAME + '-' + str(time())) self.p.run() print 'finish child' else: # Parent print 'Father' pids = (os.getpid(), self.children_pid) print "parent: %d, child: %d" % pids os.waitpid(self.children_pid, 0) self.monitor()
| (_| | | | \__ \ |_) | | | |_| | || __/ \__,_|_| |_|___/_.__/|_| \__,_|\__\___| Python3 Recode: By NovaCygni By d4rkcat ''') if len(argv) == 1: parser.print_help() exit() maxthreads = 40 if args.threads: maxthreads = args.threads signal.signal(signal.SIGINT, killpid) domain = args.url maked = "mkdir -p logs" process = subprocess.Popen(maked.split(), stdout=subprocess.PIPE) poutput = process.communicate()[0] subdomains = [line.strip() for line in open(args.wordlist, 'r')] dnsservers = [ "8.8.8.8", "8.8.4.4", "4.2.2.1", "4.2.2.2", "4.2.2.3", "4.2.2.4", "4.2.2.5", "4.2.2.6", "4.2.35.8", "4.2.49.4", "4.2.49.3", "4.2.49.2", "209.244.0.3", "209.244.0.4", "208.67.222.222", "208.67.220.220", "192.121.86.114", "192.121.121.14", "216.111.65.217", "192.76.85.133", "151.202.0.85" ] resolver = dns.resolver.Resolver() resolver.nameservers = dnsservers queueLock = Lock()
def comportDetect(): dev = list(serial.tools.list_ports.comports()) if not dev: return False else: return dev ports = comportDetect() tmpports = [] portcount = 0 for p in ports: print(portcount, p) tmpports.append(p) portcount = portcount + 1 input = input('Port to read? ') print(tmpports[2].device) ser = serial.Serial(tmpports[int(input)].device) try: while True: arduino = ser.readline() print(arduino) except KeyboardInterrupt: signal.signal(signal.SIGINT, signal_handler)
\__,_|\__,_|_| |_| |_|_|_| |_|_| |_|_| |_|\__,_|\___|_| Python3 Recode: By NovaCygni By d4rkcat ''') if len(argv) == 1: parser.print_help() exit() import http.client, httplib2 domain = args.url url = str(domain.strip()) adminlist = [line.strip() for line in open(args.wordlist, 'r')] signal.signal(signal.SIGINT, killpid) queueLock = Lock() workQueue = queue.Queue(len(adminlist)) found = [] threads = [] exitFlag = 0 threadID = 1 maxthreads = 40 if args.threads: maxthreads = args.threads queueLock.acquire() for word in adminlist: workQueue.put(word) queueLock.release()
args = parseArgs() context = Context.create() if args.loglevel: context.log_level = LogLevel.get(int(args.loglevel)) for d in args.driver: t = DeviceThread(context, d) devicehashes.append(t.hash) threads.append(t) deviceinfo = collectDeviceInfo() for t in threads: t.start() startWorkerThread() signal.signal(signal.SIGINT, exitHandler) try: while True: now = time.time() for k, v in autoget.items(): if (v["next"] < now): print("Excute " + str(k)) handleCmd({"cmd": "get", "key": k, "hash": "*"}) v["next"] = now + v["interval"] / 1000 break # just one request time.sleep(0.05) except: exitHandler(False, False)