python watchdog gui_python watchdog运行的不仅仅是

我试图学习python watchdog,但我有点困惑,为什么我设置的作业运行不止一次。所以,这是我的设置:#handler.py

import os

from watchdog.events import FileSystemEventHandler

from actions import run_something

def getext(filename):

return os.path.splitext(filename)[-1].lower()

class ChangeHandler(FileSystemEventHandler):

def on_any_event(self, event):

if event.is_directory:

return

if getext(event.src_path) == '.done':

run_something()

else:

print "event not directory.. exiting..."

pass

观察者的设置如下:

^{pr2}$

最后,这样的行动:#actions.py

import os

import subprocess

def run_something():

output = subprocess.check_output(['./run.sh'])

print output

return None

…其中./run.sh只是当在/path/to/some/directory/bin上找到扩展名为.done的文件时,我想运行的shell脚本#run.sh

#!/bin/bash

echo "Job Start: $(date)"

rm -rf /path/to/some/directory/bin/job.done # remove the .done file

echo "Job Done: $(date)"

但是,当我发出python observer.py,然后对/path/to/some/directory/bin执行touch job.done时,我发现我的shell脚本./run.sh运行了三次,而不是一次。。在

我很困惑,为什么这会运行三次而不是一次(我确实删除了bash脚本上的job.done文件)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值