0

I want to use pyinotify to watch changes on the filesystem. If a file has changed, I want to update my database file accordingly (re-read tags, other information...)

I put the following code in my app's 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)
....

This works great when django is run with ''./manage.py runserver''. However, when run as ''./manage.py runfcgi'' django won't start. There is no error message, it just hangs and won't daemonize, probably at the line ''notifier.start()''.

When I run ''./manage.py runfcgi method=threaded'' and enable the line ''notifier.setDaemon(True)'', then the notifier thread is stopped (isAlive() = False).

What is the correct way to start endless threads together with django when django is run as fcgi? Is it even possible?

user1283043
  • 190
  • 1
  • 1
  • 8
  • Uhm, you do know what _infinite_ means? I would say it's even theoretically impossible to create infinite number of threads (unless you have a computer with infinite resources (RAM, cores, etc.)). – Some programmer dude Jul 27 '12 at 12:56
  • I changed the title from _infinite_ to _endless_ . You are right- it was very ambiguous. – user1283043 Jul 27 '12 at 13:07

1 Answers1

0

Well, duh. Never start an own, endless thread besides django. I use celery, where it works a bit better to run such threads.

user1283043
  • 190
  • 1
  • 1
  • 8