wxPython GUI与现有进程

2024-10-02 22:29:18 发布

您现在位置:Python中文网/ 问答频道 /正文

我最初想用Python和watchdog和Process创建一个文件监视系统。在我的程序中,我有一个FileSystemEventHandler子类(DirectoryMonitorHandler)来监视文件夹的更改。声明一个全局队列,以便DirectoryMonitorHandler将项插入队列中。然后队列是can Process子类,该子类用于处理DirectoryMonitorHandler插入的对象。以下是我的程序中的代码片段:

if __name__ == "__main__":
    # The global queue that is shared by the DirectoryMonitorHandler and BacklogManager is created
    q = Queue()

    # Check if source directory exists
    if os.path.exists(source):
        # DirectoryMonitorHandler is initialized with the global queue as the input
        monitor_handler = DirectoryMonitorHandler(q)
        monitor = polling.PollingObserver()
        monitor.schedule(monitor_handler, source, recursive = True)
        monitor.start()

        # BacklogManager is initialized with the global queue as the input
        mamanger = BacklogManager(q)
        mamanger.start()

        mamanger.join()
        monitor.join()
    else:
        handleError('config.ini', Error.SourceError)

这个程序运行良好,但现在我决定添加一个GUI组件。以下是我目前所掌握的情况:

^{pr2}$

这个窗口工作正常,但我不确定如何将这两个组件集成在一起。wxpythongui是否应该作为单独的进程运行?我在想我可以创建一个MonitorWindow的实例,在它们启动之前将其传递给DirectoryMonitorHandler和{}。在

我也读过这篇http://wiki.wxpython.org/LongRunningTasks,它解释了wxPython窗口如何与线程一起工作,但是我需要它来处理进程。另一个可能的解决方案是,我必须从Window类中创建并启动DirectoryMonitorHandler和{}的实例。你们觉得怎么样?在


Tags: the程序sourceif队列queueisexists
1条回答
网友
1楼 · 发布于 2024-10-02 22:29:18

wxPython本身应该是主进程,它应该启动监视文件系统的长时间运行的进程。如果您正在使用多处理模块,那么您可能应该阅读以下内容之一:

您提到的长时间运行的Tasks wiki文章对于学习如何使用wxPython和线程非常有用。我已经在那篇文章中多次使用这些技巧,没有任何问题。在

相关问题 更多 >