]> www.vanbest.org Git - motioneye-debian/commitdiff
mjpgclient: added a dedicated start_gc() function
authorCalin Crisan <ccrisan@gmail.com>
Sun, 18 Oct 2015 13:57:57 +0000 (16:57 +0300)
committerCalin Crisan <ccrisan@gmail.com>
Sun, 18 Oct 2015 13:57:57 +0000 (16:57 +0300)
motioneye/mjpgclient.py
motioneye/server.py

index 093c3cdab0ae5a083b495dea7ed1c7ed7b44ff46..01186e67d6ad7c0c04811839286a28858d4bf753 100644 (file)
@@ -212,7 +212,10 @@ class MjpgClient(iostream.IOStream):
 
 def _garbage_collector():
     logging.debug('running garbage collector for mjpg clients...')
-    
+
+    io_loop = ioloop.IOLoop.instance()
+    io_loop.add_timeout(datetime.timedelta(seconds=settings.MJPG_CLIENT_TIMEOUT), _garbage_collector)
+
     now = datetime.datetime.utcnow()
     for client in MjpgClient.clients.values():
         camera_id = client._camera_id
@@ -256,9 +259,6 @@ def _garbage_collector():
 
             continue
         
-    io_loop = ioloop.IOLoop.instance()
-    io_loop.add_timeout(datetime.timedelta(seconds=settings.MJPG_CLIENT_TIMEOUT), _garbage_collector)
-
 
 def get_jpg(camera_id):
     if camera_id not in MjpgClient.clients:
@@ -299,6 +299,7 @@ def close_all(invalidate=False):
         MjpgClient.last_erroneous_close_time = 0
 
 
-# schedule the garbage collector
-io_loop = ioloop.IOLoop.instance()
-io_loop.add_timeout(datetime.timedelta(seconds=settings.MJPG_CLIENT_TIMEOUT), _garbage_collector)
+def start_gc():
+    # schedule the garbage collector
+    io_loop = ioloop.IOLoop.instance()
+    io_loop.add_timeout(datetime.timedelta(seconds=settings.MJPG_CLIENT_TIMEOUT), _garbage_collector)
index cfa29145228172defb82c10a36588208eaf88eb4..6e27608d9ed0c39227a721391b655fc8c640386d 100644 (file)
@@ -333,6 +333,13 @@ def start_thumbnailer():
     logging.info('thumbnailer started')
 
 
+def start_mjpg_client_gc():
+    import mjpgclient
+
+    mjpgclient.start_gc()
+    logging.info('mjpg client garbage collector started')
+
+
 def parse_options(parser, args):
     parser.add_argument('-b', help='start the server in background (daemonize)',
             action='store_true', dest='background', default=False)
@@ -362,12 +369,17 @@ def run():
     else:
         start_motion()
 
-    start_cleanup()
+    if settings.CLEANUP_INTERVAL:
+        start_cleanup()
+        
     start_wsswitch()
 
     if settings.THUMBNAILER_INTERVAL:
         start_thumbnailer()
 
+    if settings.MJPG_CLIENT_TIMEOUT:
+        start_mjpg_client_gc()
+
     template.add_context('static_path', settings.BASE_PATH + '/static/')
     
     application = Application(handler_mapping, debug=False, log_function=_log_request,