當前位置: 首頁>>代碼示例>>Python>>正文


Python thread.interrupt_main方法代碼示例

本文整理匯總了Python中thread.interrupt_main方法的典型用法代碼示例。如果您正苦於以下問題:Python thread.interrupt_main方法的具體用法?Python thread.interrupt_main怎麽用?Python thread.interrupt_main使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在thread的用法示例。


在下文中一共展示了thread.interrupt_main方法的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: _schedule_batch

# 需要導入模塊: import thread [as 別名]
# 或者: from thread import interrupt_main [as 別名]
def _schedule_batch(self, client_ids, fetches):
    """Schedules a single batch for execution."""
    with timer_counter(self.counters, 'executor-inference'):
      try:
        ret = self.session.run(
            fetches, {
                self.model.input_seed: self.input_seed,
                self.model.input_patches: self.input_image})
      except Exception as e:  # pylint:disable=broad-except
        logging.exception(e)
        # If calling TF didn't work (faulty hardware, misconfiguration, etc),
        # we want to terminate the whole program.
        thread.interrupt_main()
        raise e

    with timer_counter(self.counters, 'executor-output'):
      with self._lock:
        for i, client_id in enumerate(client_ids):
          try:
            self.outputs[client_id].put(
                {k: v[i, ...] for k, v in ret.items()})
          except KeyError:
            # This could happen if a client unregistered itself
            # while inference was running.
            pass 
開發者ID:google,項目名稱:ffn,代碼行數:27,代碼來源:executor.py

示例2: run

# 需要導入模塊: import thread [as 別名]
# 或者: from thread import interrupt_main [as 別名]
def run(self):
        exists = os.path.exists
        mtime = lambda path: os.stat(path).st_mtime
        files = dict()

        for module in list(sys.modules.values()):
            path = getattr(module, '__file__', '')
            if path[-4:] in ('.pyo', '.pyc'): path = path[:-1]
            if path and exists(path): files[path] = mtime(path)

        while not self.status:
            if not exists(self.lockfile)\
            or mtime(self.lockfile) < time.time() - self.interval - 5:
                self.status = 'error'
                thread.interrupt_main()
            for path, lmtime in list(files.items()):
                if not exists(path) or mtime(path) > lmtime:
                    self.status = 'reload'
                    thread.interrupt_main()
                    break
            time.sleep(self.interval) 
開發者ID:Autodesk,項目名稱:arnold-usd,代碼行數:23,代碼來源:__init__.py

示例3: Pinging_Thread

# 需要導入模塊: import thread [as 別名]
# 或者: from thread import interrupt_main [as 別名]
def Pinging_Thread(self):
		print "[+] Starting Ping thread"
		wait = True
		while 1:							#loop forever
			if wait: sleep(ping_delay)		#send ping to server interval
			self.mutex_http_req.acquire()	#Ensure that the other thread is not making a request at this time
			try:
				resp_data=HTTPreq(url,"")	#Read response
				if verbose: v_print(pings_n=1)
				if resp_data:					#If response had data write them to socket
					if verbose: v_print(received_d_pt=len(resp_data))
					self.send(resp_data)		#write to socket
					resp_data=""				#clear data
					#not clearing flag in case more data avail.
					wait = False				#Dont wait: if there was data probably there are more
				else:
					wait = True
			finally:
				self.mutex_http_req.release()	
		print "[-] Pinging Thread Exited"
		thread.interrupt_main()		#Signal main thread -> exits 
開發者ID:euphrat1ca,項目名稱:fuzzdb-collect,代碼行數:23,代碼來源:proxy.py

示例4: Threaded_request

# 需要導入模塊: import thread [as 別名]
# 或者: from thread import interrupt_main [as 別名]
def Threaded_request(url,cj):
	#Sends connection options to the webshell
	#In php this thread will stall to keep the connection alive (will not receive response)
	#In other langs [OK] is received
	opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj))
	global remote_ip

	print '[+] Spawning keep-alive thread'	
	if remote_ip:
		resp = HTTPreq(url+"&port="+str(remote_port)+"&ip="+str(remote_ip))
	else:
		resp = HTTPreq(url+"&port="+str(remote_port))
	if(resp != '[OK]'):				#if ok is not received something went wrong (if nothing is received: it's a PHP webshell)
		print resp
		print '[-] Keep-alive thread exited'
		thread.interrupt_main()
	else:							#If ok is received (non-php webshell): Thread not needed
		print '[-] Keep-alive thread not required' 
開發者ID:euphrat1ca,項目名稱:fuzzdb-collect,代碼行數:20,代碼來源:proxy.py

示例5: exit_after

# 需要導入模塊: import thread [as 別名]
# 或者: from thread import interrupt_main [as 別名]
def exit_after(s):
    """
    Use as decorator to exit process if
    function takes longer than s seconds.

    Direct call is available via exit_after(TIMEOUT_IN_S)(fce)(args).

    Inspired by https://stackoverflow.com/a/31667005
    """

    def outer(fn):
        def inner(*args, **kwargs):
            timer = threading.Timer(s, thread.interrupt_main)
            timer.start()
            try:
                result = fn(*args, **kwargs)
            except KeyboardInterrupt:
                raise TimeoutError("Function '{}' hit the timeout ({}s).".format(fn.__name__, s))
            finally:
                timer.cancel()
            return result

        return inner

    return outer 
開發者ID:user-cont,項目名稱:colin,代碼行數:27,代碼來源:cmd_tools.py

示例6: run

# 需要導入模塊: import thread [as 別名]
# 或者: from thread import interrupt_main [as 別名]
def run(self):
        exists = os.path.exists
        mtime = lambda path: os.stat(path).st_mtime
        files = dict()

        for module in sys.modules.values():
            path = getattr(module, '__file__', '')
            if path[-4:] in ('.pyo', '.pyc'): path = path[:-1]
            if path and exists(path): files[path] = mtime(path)

        while not self.status:
            if not exists(self.lockfile)\
            or mtime(self.lockfile) < time.time() - self.interval - 5:
                self.status = 'error'
                thread.interrupt_main()
            for path, lmtime in files.iteritems():
                if not exists(path) or mtime(path) > lmtime:
                    self.status = 'reload'
                    thread.interrupt_main()
                    break
            time.sleep(self.interval) 
開發者ID:zhangzhengde0225,項目名稱:VaspCZ,代碼行數:23,代碼來源:bottle.py

示例7: run

# 需要導入模塊: import thread [as 別名]
# 或者: from thread import interrupt_main [as 別名]
def run(self):
        exists = os.path.exists
        mtime = lambda p: os.stat(p).st_mtime
        files = dict()

        for module in list(sys.modules.values()):
            path = getattr(module, '__file__', '')
            if path[-4:] in ('.pyo', '.pyc'): path = path[:-1]
            if path and exists(path): files[path] = mtime(path)

        while not self.status:
            if not exists(self.lockfile)\
            or mtime(self.lockfile) < time.time() - self.interval - 5:
                self.status = 'error'
                thread.interrupt_main()
            for path, lmtime in list(files.items()):
                if not exists(path) or mtime(path) > lmtime:
                    self.status = 'reload'
                    thread.interrupt_main()
                    break
            time.sleep(self.interval) 
開發者ID:brycesub,項目名稱:silvia-pi,代碼行數:23,代碼來源:bottle.py

示例8: write_rtt

# 需要導入模塊: import thread [as 別名]
# 或者: from thread import interrupt_main [as 別名]
def write_rtt(jlink):
    """Writes kayboard input to JLink RTT buffer #0.

    This method is a loop that blocks waiting on stdin. When enter is pressed,
    LF and NUL bytes are added to the input and transmitted as a byte list.
    If the JLink is disconnected, it will exit gracefully. If any other
    exceptions are raised, they will be caught and re-raised after interrupting
    the main thread.

    Args:
      jlink (pylink.JLink): The JLink to write to.

    Raises:
      Exception on error.
    """
    try:
        while jlink.connected():
            bytes = list(bytearray(input(), "utf-8") + b"\x0A\x00")
            bytes_written = jlink.rtt_write(0, bytes)
    except Exception:
        print("IO write thread exception, exiting...")
        thread.interrupt_main()
        raise 
開發者ID:square,項目名稱:pylink,代碼行數:25,代碼來源:rtt.py

示例9: _terminate_execution

# 需要導入模塊: import thread [as 別名]
# 或者: from thread import interrupt_main [as 別名]
def _terminate_execution(self):
        # called from receiverthread
        self._trace("shutting down execution pool")
        self._execpool.trigger_shutdown()
        if not self._execpool.waitall(5.0):
            self._trace("execution ongoing after 5 secs," " trying interrupt_main")
            # We try hard to terminate execution based on the assumption
            # that there is only one gateway object running per-process.
            if sys.platform != "win32":
                self._trace("sending ourselves a SIGINT")
                os.kill(os.getpid(), 2)  # send ourselves a SIGINT
            elif interrupt_main is not None:
                self._trace("calling interrupt_main()")
                interrupt_main()
            if not self._execpool.waitall(10.0):
                self._trace(
                    "execution did not finish in another 10 secs, " "calling os._exit()"
                )
                os._exit(1) 
開發者ID:pytest-dev,項目名稱:execnet,代碼行數:21,代碼來源:gateway_base.py

示例10: _loop_adjusting_instances

# 需要導入模塊: import thread [as 別名]
# 或者: from thread import interrupt_main [as 別名]
def _loop_adjusting_instances(self):
    """Loops until the Module exits, reloading, adding or removing Instances."""
    while not self._quit_event.is_set():
      if self.ready:
        if self._automatic_restarts:
          self._handle_changes(_CHANGE_POLLING_MS)
        else:
          time.sleep(_CHANGE_POLLING_MS/1000.0)
        try:
          self._adjust_instances()
        except Exception as e:  # pylint: disable=broad-except
          logging.error(e.message)
          # thread.interrupt_main() throws a KeyboardInterrupt error in the main
          # thread, which triggers devappserver.stop() and shuts down all other
          # processes.
          thread.interrupt_main()
          break 
開發者ID:GoogleCloudPlatform,項目名稱:python-compat-runtime,代碼行數:19,代碼來源:module.py

示例11: run

# 需要導入模塊: import thread [as 別名]
# 或者: from thread import interrupt_main [as 別名]
def run(self):
        exists = os.path.exists
        mtime = lambda p: os.stat(p).st_mtime
        files = dict()

        for module in list(sys.modules.values()):
            path = getattr(module, '__file__', '') or ''
            if path[-4:] in ('.pyo', '.pyc'): path = path[:-1]
            if path and exists(path): files[path] = mtime(path)

        while not self.status:
            if not exists(self.lockfile)\
            or mtime(self.lockfile) < time.time() - self.interval - 5:
                self.status = 'error'
                thread.interrupt_main()
            for path, lmtime in list(files.items()):
                if not exists(path) or mtime(path) > lmtime:
                    self.status = 'reload'
                    thread.interrupt_main()
                    break
            time.sleep(self.interval) 
開發者ID:DandyDev,項目名稱:slack-machine,代碼行數:23,代碼來源:bottle.py


注:本文中的thread.interrupt_main方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。