python创建窗口接收消息延迟_Python监视程序窗口等待复制完成

我正在使用Windows2012服务器上的PythonWatchdog模块监视共享驱动器上出现的新文件。当监视程序注意到新文件时,它将启动数据库还原过程。

不过,看起来看门狗会在创建文件时尝试将其还原,而不是等到文件复制到共享驱动器完成。因此,我将事件更改为on_modified,但有两个on_modified事件,一个是文件最初被复制时,另一个是文件完成复制时。

如何处理两个on_modified事件,使其仅在复制到共享驱动器的文件完成时触发?

如果同时将多个文件复制到共享驱动器,会发生什么情况?

这是我的密码import time

import subprocess

from watchdog.observers import Observer

from watchdog.events import FileSystemEventHandler

class NewFile(FileSystemEventHandler):

def process(self, event):

if event.is_directory:

return

if event.event_type == 'modified':

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

load_pgdump(event.src_path)

def on_modified(self, event):

self.process(event)

def getext(filename):

"Get the file extension"

file_ext = filename.split(".",1)[1]

return file_ext

def load_pgdump(src_path):

restore = 'pg_restore command ' + src_path

subprocess.call(restore, shell=True)

def main():

event_handler = NewFile()

observer = Observer()

observer.schedule(event_handler, path='Y:\\', recursive=True)

observer.start()

try:

while True:

time.sleep(1)

except keyboardInterrupt:

observer.stop()

observer.join()

if __name__ == '__main__':

main()

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值