python watchdog休眠_Python看门狗测量时间事件(Python Watchdog Measure Time Events)

本文档介绍如何使用Python的Watchdog库来测量事件调用之间的时间间隔。通过创建一个自定义的Handler类并在`on_any_event`方法中记录事件时间,可以计算出两次事件发生之间的差异。这有助于在满足特定时间条件时执行操作,例如当事件间隔达到5秒时触发某个功能。
摘要由CSDN通过智能技术生成

Python看门狗测量时间事件(Python Watchdog Measure Time Events)

我试图将一个名为Watchdog的模块实现到一个项目中。 我正在寻找一种方法来测量Watchdog中的事件调用之间的时间间隔。

if timebetweenevents == 5 seconds:

dothething()

谢谢,

查尔斯

编辑:

我正在使用Python 3.5.0

以下是我在LINK上工作的代码。

我可以打印出当前事件的时间,但从上次事件开始持续的时间并测量自上次事件之后的时间的最佳方法是什么?

I'm trying to implement a module called Watchdog into a project. I'm looking for a way I can measure time between event calls within Watchdog.

if timebetweenevents == 5 seconds:

dothething()

Thank you,

Charles

Edit:

I'm using Python 3.5.0

Here's what the code I was working on LINK.

I can print out the current time of the event, but what is the best way to hold on to the time from the last event and then measure the time between since the last event?

原文:https://stackoverflow.com/questions/40031080

2020-03-03 09:20

满意答案

您可以修改Handler类以记录上次调用的时间。

init方法只是将值初始化为当前时间。 您还需要使方法on_any_event成为非静态方法

class Handler(FileSystemEventHandler):

event_time=0

def __init__(self):

self.event_time=time.time()

def on_any_event(self, event):

now=time.time()

timedelta=now-self.event_time

self.event_time=now

print(timedelta)

You can modify your Handler class to have a record of the time of the last call.

init method just initialises the value to the current time. You will also need to make the method on_any_event a non static method

class Handler(FileSystemEventHandler):

event_time=0

def __init__(self):

self.event_time=time.time()

def on_any_event(self, event):

now=time.time()

timedelta=now-self.event_time

self.event_time=now

print(timedelta)

2016-10-14

相关问答

如果我在你的位置,我会在5秒内发送一次本地UDP数据包。 如果您的架构是模块化的,您可以从每个模块向看门狗模块发送信号(以确保每个模块都在运行)。 我认为最好的方法是评估问题并使LabVIEW应用程序运行稳定。 当然,代码中有一些东西会导致LabVIEW崩溃(例如,某些队列已满,而您的编写器端点无限期等待)。 If I was on your place I would just send local UDP packet once a 5 seconds. IF your architectur...

如果软件没有(定期)阻止关机,HW看门狗会自动重置系统; 当给定CPU时间时,SW看门狗OTOH只能做某些事情。 因此,它必须定期检查系统是否需要重新设置,并通过编程HW来响应。 最终的结果是,SW看门狗无法响应整个系统崩溃。 典型的编程模型是: HW watchdog: [HW circuit]

--

vs.

--

SW watchdog: [Low priority SW proc...

试试github上的例子: https : //github.com/gorakhargosh/watchdog 这个例子似乎起作用,而不是文档站点上没有的那个。 Try the example on github: https://github.com/gorakhargosh/watchdog This example seems to work as opposed to the one on the docs site that does not.

看门狗定时器的使用特定于http://www.arduinolibraries.info/libraries/free-rtos上的“官方”Arduino端口,而不是FreeRTOS的特性。 有关实施详情, 请访问https://feilipu.me/2015/11/24/arduino_freertos/ 。 看门狗定时器用作系统节拍定时器(因为所有其他定时器都配置为供Arduino框架使用)。 在这种情况下,您不能将看门狗定时器用于其正常用途,如果您异步重置它,肯定会干扰调度程序定时。 这种看...

将您的文件路径替换为父文件夹路径。 observer.schedule(event_handler, path='C:/Email_forwarding/Attachments/Sales', recursive=False) Replace your file path to the parent folder path. observer.schedule(event_handler, path='C:/Email_forwarding/Attachments/Sales', recursiv...

简短回答: f = open(... , 'w')生成一个FileCreatedEvent , f.flush()或f.close()可以生成一个FileModifiedEvent 。 所以是的,创建一个文件通常会生成FileCreatedEvent和FileModifiedEvents 。 您是否可以安全地忽略FileCreatedEvents取决于您正在尝试执行的操作。 如果您有兴趣在创建文件时作出反应,那么您需要处理FileCreatedEvents,并且可能忽略FileModifiedEv...

根据源代码 , fnmatch正在引擎盖下使用。 fnmatch只能做UNIX全局模式匹配。 这意味着你可能有更好的运气*.jpg不是\w+[.]jpeg Based on the source code, fnmatch is being used under the hood. fnmatch can only do UNIX glob-style pattern matching. Which means you may have better luck with *.jpg than \w...

对于python> = 2.6的版本,watchdog使用它的OrderedSet。 修改fatuhoku的路径功能如下; @property

def paths(self):

if sys.version_info >= (2, 6, 0):

return watchdog.utils.bricks.OrderedSet()

return set()

For versions of python >= 2.6 watchdog uses it's Ordered...

要调试监视程序脚本,打印监视程序作为事件看到的内容非常有用。 一个文件编辑或CLI命令(例如touch )可能导致多个监视程序事件。 例如,如果插入print语句: class ChangeHandler(FileSystemEventHandler):

def on_any_event(self, event):

print(event)

记录每个事件,运行 % touch job.done

生成 2014-12-24 13:11:02 -

您可以修改Handler类以记录上次调用的时间。 init方法只是将值初始化为当前时间。 您还需要使方法on_any_event成为非静态方法 class Handler(FileSystemEventHandler):

event_time=0

def __init__(self):

self.event_time=time.time()

def on_any_event(self, event):

now=time.time()

...

相关文章

erver-Sent Events - 单向的信息处理.一个SSE(server send event

...

http://engineering.linkedin.com/distributed-systems

...

里面有些公式和矩阵无法在电脑上书写, 故用纸笔记录了一些笔记, 比如公式的推算, 注意要点等. 由于电

...

mod_python: the long story - Grisha Trubetskoy

...

Python实现用Hadoop的map/reduce对web日志进行统计 日志格式 61.160.24

...

最近开发微信接口,配合开发弄了这个微信服务端的模拟以方便调试。 #-*-cod

...

昨天QQ群里提了一个Hadoop运行效率分配的问题,总结一下,写个文章。集群使用hadoop-1.0.

...

初识spark-基本概念和例子 | _yiihsia[互联网后端技术] 初

...

最近无聊,想玩玩微信的公众平台,后来发现乐趣无穷啊~ 使用的工具,python 新浪SAE平台,微信的

...

最新问答

如果启用了复制处理程序,请确保将其置于其中一个安全角色之后。 我见过人们做的另一件事是在不同的端口上运行admin。 最好在需要auth的页面上使用SSL,这样你就不会发送明确的密码,因此管理和复制将发生在8443上,而常规查询将在8080上发生。 如果您要签署自己的证书,请查看此有用的SO页面: 如何在特定连接上使用不同的证书? I didn't know that /admin was the context for SOLR admin because /admin does not re

第一:在您的样本中,您有: 但是你在询问 //td[@class=‘CarMiniProfile-TableHeader’] (注意TableHeader中的大写'T')。 xpath区分大小写。 第二:通过查询// td [@ class ='CarMiniProfile-TableHeader'] / td,你暗示你在外部td中有一个'td'元素,而它们是兄弟姐妹。 有很多方法可以在这里获得制作和模型

这是你的答案: http://jsfiddle.net/gPsdk/40/ .preloader-container { position: absolute; top: 0px; right: 0px; bottom: 0px; left: 0px; background: #FFFFFF; z-index: 5; opacity: 1; -webkit-transition: all 500ms ease-out;

问题是,在启用Outlook库引用的情况下, olMailItem是一个保留常量,我认为当您将Dim olMailItem as Outlook.MailItem ,这不是问题,但是尝试设置变量会导致问题。 以下是完整的解释: 您已将olMailItem声明为对象变量。 在赋值语句的右侧,在将其值设置为对象的实例之前,您将引用此Object 。 这基本上是一个递归错误,因为你有对象试图自己分配自己。 还有另一个潜在的错误,如果之前已经分配了olMailItem ,这个语句会引发另一个错误(可能是

我建议使用wireshark http://www.wireshark.org/通过记录(“捕获”)设备可以看到的网络流量副本来“监听”网络上发生的对话。 当您开始捕获时,数据量似乎过大,但如果您能够发现任何看起来像您的SOAP消息的片段(应该很容易发现),那么您可以通过右键单击并选择来快速过滤到该对话'关注TCP Stream'。 然后,您可以在弹出窗口中查看您编写的SOAP服务与Silverlight客户端之间的整个对话。 如果一切正常,请关闭弹出窗口。 作为一个额外的好处,wireshar

Android默认情况下不提供TextView的合理结果。 您可以使用以下库并实现适当的aligntment。 https://github.com/navabi/JustifiedTextView Android Does not provide Justified aligntment of TextView By default. You can use following library and achieve proper aligntment. https://github.com/

你的代码适合我: class apples { public static void main(String args[]) { System.out.println("Hello World!"); } } 我将它下载到c:\ temp \ apples.java。 以下是我编译和运行的方式: C:\temp>javac -cp . apples.java C:\temp>dir apples Volume in drive C is HP_PAV

12个十六进制数字(带前导0x)表示48位。 那是256 TB的虚拟地址空间。 在AMD64上阅读wiki(我假设你在上面,对吗?)架构http://en.wikipedia.org/wiki/X86-64 12 hex digits (with leading 0x) mean 48 bits. That is 256 TB of virtual address space. Read wiki on AMD64 (I assume that you are on it, right?) ar

这将取决于你想要的。 对象有两种属性:类属性和实例属性。 类属性 类属性对于类的每个实例都是相同的对象。 class MyClass: class_attribute = [] 这里已经为类定义了MyClass.class_attribute ,您可以使用它。 如果您创建MyClass实例,则每个实例都可以访问相同的class_attribute 。 实例属性 instance属性仅在创建实例时可用,并且对于类的每个实例都是唯一的。 您只能在实例上使用它们。 在方法__init__中定

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值