本文整理汇总了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
示例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)
示例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
示例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'
示例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
示例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)
示例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)
示例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
示例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)
示例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
示例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)