Python在创建时读取和处理文件

Python在创建时读取和处理文件,python,multithreading,multiprocessing,eventhandler,python-watchdog,Python,Multithreading,Multiprocessing,Eventhandler,Python Watchdog,我使用了watchdog来监听目录,并在添加新文件时读取和处理它。在on_created事件中,我可以在添加所有文件名时获取它们,但处理每个文件需要一些时间(几秒钟)。处理file1应在获取新文件之前完成。我测试了多线程,但没有得到正确的答案 我如何处理这个问题 from watchdog.observers import Observer from watchdog.events import FileSystemEventHandler def mainfunc(src_path):

我使用了watchdog来监听目录,并在添加新文件时读取和处理它。在
on_created
事件中,我可以在添加所有文件名时获取它们,但处理每个文件需要一些时间(几秒钟)。处理
file1
应在获取新文件之前完成。我测试了多线程,但没有得到正确的答案

我如何处理这个问题

from watchdog.observers import Observer
from watchdog.events import FileSystemEventHandler
def mainfunc(src_path):
    #for runing need 60seconds
class MyHandler(FileSystemEventHandler):
    def on_created(self, event):
        t = threading.Thread(target=mainfunc(event.src_path))
输出:

/root/PycharmProjects/f1.nc
finish :at 2020-02-20 13:58:39.352510
/root/PycharmProjects/f2.nc
finish :  at 2020-02-20 13:59:12.404122
t=threading.Thread(target=mainfunc(event.src_path))
-线程不会在创建时启动,您应该
t.start()
它们
t=threading.Thread(target=mainfunc(event.src_path))
-线程不会在创建时启动,您应该
t.start()
它们