Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/332.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 当django作为fcgi运行时,启动无限线程的正确方法是什么?_Python_Django_Fastcgi_Pyinotify - Fatal编程技术网

Python 当django作为fcgi运行时,启动无限线程的正确方法是什么?

Python 当django作为fcgi运行时,启动无限线程的正确方法是什么?,python,django,fastcgi,pyinotify,Python,Django,Fastcgi,Pyinotify,我想使用pyinotify监视文件系统上的更改。如果文件已更改,我希望相应地更新数据库文件(重新读取标记、其他信息…) 我在应用程序的signals.py中添加了以下代码 import pyinotify .... # create filesystem watcher in seperate thread wm = pyinotify.WatchManager() notifier = pyinotify.ThreadedNotifier(wm, ProcessInotifyEv

我想使用pyinotify监视文件系统上的更改。如果文件已更改,我希望相应地更新数据库文件(重新读取标记、其他信息…)

我在应用程序的signals.py中添加了以下代码

import pyinotify
....

# create filesystem watcher in seperate thread
wm       = pyinotify.WatchManager()
notifier = pyinotify.ThreadedNotifier(wm, ProcessInotifyEvent())
# notifier.setDaemon(True)
notifier.start()
mask     = pyinotify.IN_CLOSE_WRITE | pyinotify.IN_CREATE | pyinotify.IN_MOVED_TO | pyinotify.IN_MOVED_FROM
dbgprint("Adding path to WatchManager:", settings.MUSIC_PATH)
wdd      = wm.add_watch(settings.MUSIC_PATH, mask, rec=True, auto_add=True)

def connect_all():
    """
    to be called from models.py
    """
    rescan_start.connect(rescan_start_callback)
    upload_done.connect(upload_done_callback)
....
当django与“”/manage.py runserver“”一起运行时,这非常有效。但是,当以“”运行/manage.py runfcgi“”时,django将不会启动。没有错误消息,它只是挂起并且不会守护,可能在“notifier.start()”行

当我运行“”/manage.py runfcgi method=threaded“”并启用行“notifier.setDaemon(True)”时,通知程序线程将停止(isAlive()=False)


当django作为fcgi运行时,使用django启动无限线程的正确方法是什么?有可能吗?

嗯,嗯。除了django,永远不要开始一个自己的、无止境的线程。我用芹菜,在那里运行这样的线程效果更好。

Uhm,你知道无限是什么意思吗?我想说,理论上甚至不可能创建无限多的线程(除非你有一台拥有无限资源(RAM、内核等)的计算机)。我将标题从无限改为无限。你是对的,这是非常模棱两可的。