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

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如何修复尝试将用户签名到服务器主机时出现的“字符串无法转换为json对象”错误?   控制台Java:不使用新行更新命令行中的文本   java servlet接收xml数据时,出现错误   使用REST API在Bitbucket中复制或复制存储库   java如何在JavaFX中对齐一行?   java如何在活动中显示通过服务获得的数据?   返回BigDecimal作为字符串:返回int   java组织。openqa。硒。InvalidSelectorException:尝试查找元素时选择器无效   java仅在阻塞状态下通知和通知所有影响线程   java JBOSS无法启动部署   java方法的返回值能保证类型安全吗?   JavaeShadoop序列化组织。阿帕奇。hadoop。木卫一。短写失败   java如果我在同一个类上同步了两个方法,它们能同时运行吗?   不使用java数据库的spring分页实现   java如何将字符串切碎成这样的数组?