Commit 794b5b06 by Victor Shnayder

Address Ike's comments on #580

parent c01f9712
...@@ -20,14 +20,16 @@ Basic structure: ...@@ -20,14 +20,16 @@ Basic structure:
3) call e.clear() to clear the state to start looking for the next modification. 3) call e.clear() to clear the state to start looking for the next modification.
4) go back to step 2 to ask about the next modification. 4) go back to step 2 to ask about the next modification.
""" """
import logging
import os import os
import sys
import time import time
import threading import threading
import atexit import atexit
import Queue import Queue
log = logging.getLogger(__name__)
_interval = 1.0 _interval = 1.0
_times = {} # path -> modification time _times = {} # path -> modification time
_events = {} # path -> event for that path _events = {} # path -> event for that path
...@@ -36,11 +38,6 @@ _queue = Queue.Queue() # used only for thread-local sleeping ...@@ -36,11 +38,6 @@ _queue = Queue.Queue() # used only for thread-local sleeping
_running = False _running = False
_lock = threading.Lock() # protects _running and writes to the _events dictionary _lock = threading.Lock() # protects _running and writes to the _events dictionary
def _restart(path):
_queue.put(True)
prefix = 'monitor (pid=%d):' % os.getpid()
print >> sys.stderr, '%s Change detected to \'%s\'.' % (prefix, path)
def _modified(path): def _modified(path):
""" """
Check whether path has been modified. If it has been, save the latest Check whether path has been modified. If it has been, save the latest
...@@ -78,10 +75,10 @@ def _monitor(): ...@@ -78,10 +75,10 @@ def _monitor():
while True: while True:
# Check modification times on files which have # Check modification times on files which have
# specifically been registered for monitoring. # specifically been registered for monitoring.
#print >> sys.stderr, "Watching %s" % (_events.keys()) #log.debug("Watching %s", _events.keys())
for path, event in _events.items(): for path, event in _events.items():
if _modified(path): if _modified(path):
# print >> sys.stderr, "%s modified" % (path) # log.debug("%s modified", path)
event.set() event.set()
# Sleep for specified interval. # Sleep for specified interval.
...@@ -128,7 +125,7 @@ def start(interval=1.0): ...@@ -128,7 +125,7 @@ def start(interval=1.0):
_lock.acquire() _lock.acquire()
if not _running: if not _running:
prefix = 'monitor (pid=%d):' % os.getpid() prefix = 'monitor (pid=%d):' % os.getpid()
print >> sys.stderr, '%s Starting change monitor.' % prefix log.info('{0}: Starting change monitor.'.format(prefix))
_running = True _running = True
_thread.start() _thread.start()
_lock.release() _lock.release()
...@@ -289,6 +289,7 @@ class XMLModuleStore(ModuleStoreBase): ...@@ -289,6 +289,7 @@ class XMLModuleStore(ModuleStoreBase):
course_dir = self.course_dir_by_id.get(course_id) course_dir = self.course_dir_by_id.get(course_id)
if not course_dir: if not course_dir:
# courses we don't know about don't need reloading # courses we don't know about don't need reloading
log.debug("unknown course_id {0}. Not reloading.".format(course_id))
return return
if self.monitoring_event[course_id].is_set(): if self.monitoring_event[course_id].is_set():
......
...@@ -69,7 +69,7 @@ Very handy: if you uncomment the `--pdb` argument in `NOSE_ARGS` in `lms/envs/te ...@@ -69,7 +69,7 @@ Very handy: if you uncomment the `--pdb` argument in `NOSE_ARGS` in `lms/envs/te
## Content development ## Content development
If you change course content, while running the LMS in dev mode, it is unnecessary to restart to refresh the modulestore. If you change course content, while running the LMS in dev mode, it is unnecessary to restart to refresh the modulestore.
Instead, hit /migrate/modules to see a list of all modules loaded, and click on links (eg /migrate/reload/edx4edx) to reload a course. Instead, hit /migrate/modules to see a list of all modules loaded, and click on links (eg /migrate/reload/edx4edx) to reload a course.
...@@ -106,7 +106,7 @@ If you need to develop something specific to our production setup, you may need ...@@ -106,7 +106,7 @@ If you need to develop something specific to our production setup, you may need
$ pip install gunicorn $ pip install gunicorn
$ gunicorn_django -b 127.0.0.1:8000 -w 4 --pythonpath=. --settings=lms.envs.dev $ gunicorn_django -b 127.0.0.1:8000 -w 4 --pythonpath=. --settings=lms.envs.dev
The `-w 4` specifies the number of worker threads. The `-w 4` specifies the number of worker threads. Note that each thread will have a copy of the modulestore in memory, so don't run with too many workers on a small box, especially if you have a lot of classes.
gunicorn won't serve static files like the django-admin site will, so if you need that, you'll also need to set up nginx and run collectstatic. gunicorn won't serve static files like the django-admin site will, so if you need that, you'll also need to set up nginx and run collectstatic.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment