错误计数器:计数超出进程边界的错误(例如网络错误),然后在超过阈值时发出修复命令。

error-counter的Python项目详细描述


错误计数器

错误计数器:计数超出进程边界的错误(例如网络错误),然后在超过阈值时发出修复命令。

如何使用

import requests
from error_counter import Counter

# reboot system when error accumulate 3 times in a low
network_error_counter = Counter("/tmp/network_error.txt")

try:
	r = requests.post(somowhere, somewhat)
except requests.ConnectionError as e:
	network_error_counter.inc_error()

if not r is None:
	# send succeeded.
	network_error_counter.reset_error()

计数器类

class Counter:
  def __init__(self, counterfile, reset_task="sudo reboot", reset_threshold=3):

#  counterfile: file name to use counter. The file is owned jointly by sevelal Counter beyond process boundary.

#  reset_task: shell command which is issued when error count is over the threshold.

#  reset_threshold: Threshold for reset_task.

  def inc_error(self):
  #	Increment error count then issue reset_task if count is over threshold

  def dec_error(self):
  # Decrement error count as 0

  def reset_error(self):
  # Reset error count as 0

下载

DownloadsDownloadsDownloads

历史记录

  • 0.1.0 2018.11.18第一版
  • 0.1.1 2018.11.18修复自述

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java使用McClickListener单击了什么元素   Java时间戳在Oracle时间戳中不同情况下存储12 PM的奇怪行为   java无法使用事件总线对运行在不同机器上的垂直体进行通信   java Mockserver:收到请求后进行回调   java无法将Json字符串转换为Map<string,Object>   java如何按升序排列输出?   java视图行,带有oracle键。jbo。在SrCategoryParentIterator中找不到键[300100120394155]   javafxmysql连接示例   java正在等待加载完成   java是否可以将同一个有状态会话bean实例注入多个其他会话bean?   java无法让万向节检测离开或进入区域   使用JavaCV和OpenCV的java提供了dyld:lazy符号绑定失败:找不到符号:__sincos_stret   xml解析无法使用Java读取xml文档   java无法更改工具栏的颜色   javaapachesshd和JSCH   java无法在firebase存储中检索图像url   java问题与executeUpdate   同一应用程序中不同活动之间的java SharedReference