本文整理汇总了Python中six.moves._thread.interrupt_main方法的典型用法代码示例。如果您正苦于以下问题:Python _thread.interrupt_main方法的具体用法?Python _thread.interrupt_main怎么用?Python _thread.interrupt_main使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类six.moves._thread
的用法示例。
在下文中一共展示了_thread.interrupt_main方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: time_limit
# 需要导入模块: from six.moves import _thread [as 别名]
# 或者: from six.moves._thread import interrupt_main [as 别名]
def time_limit(seconds):
if hasattr(signal, "SIGALRM"):
def signal_handler(signum, frame):
raise TimeoutException("Timeout after {} seconds.".format(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 TimeoutException("Timeout after {} seconds.".format(seconds))
finally:
timer.cancel()
示例2: start_network
# 需要导入模块: from six.moves import _thread [as 别名]
# 或者: from six.moves._thread import interrupt_main [as 别名]
def start_network(config):
global PREDICTOR_NETWORK
try:
PREDICTOR_NETWORK = PredictorNetwork(config)
except Exception as e:
# An error occurred loading the model; interrupt the whole server.
tf.logging.error(e)
_thread.interrupt_main()