From 999c4941248929e676e480c9cb4163b81a07b618 Mon Sep 17 00:00:00 2001
From: ale <ale@incal.net>
Date: Sat, 24 Sep 2011 11:15:45 +0100
Subject: [PATCH] catch exceptions on the file scan; use "ionice" to lower our
 i/o priority on Linux

---
 client/djrandom_client/client.py | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)

diff --git a/client/djrandom_client/client.py b/client/djrandom_client/client.py
index 590c584..003bf47 100644
--- a/client/djrandom_client/client.py
+++ b/client/djrandom_client/client.py
@@ -37,12 +37,17 @@ class FullScan(threading.Thread):
 
     def run(self):
         while True:
-            filescan.recursive_scan(self.basedir, self.queue)
+            # Do a full scan every 3 days.
+            delay = 86400 * 3
+            try:
+                filescan.recursive_scan(self.basedir, self.queue)
+            except Exception, e:
+                log.error('Error in file scan: %s' % e)
+                delay = 3600
             if self.exit_when_done:
                 self.queue.put(None)
                 break
-            # Do a full scan every 3 days.
-            time.sleep(86400 * 3)
+            time.sleep(delay)
 
 
 def run_client(server_url, music_dir, api_key, run_once, bwlimit):
@@ -59,6 +64,9 @@ def run_client(server_url, music_dir, api_key, run_once, bwlimit):
     if not run_once:
         # Run at a lower priority.
         os.nice(10)
+        if os.path.exists('/usr/bin/ionice'):
+            # Set 'idle' I/O scheduling class, we won't disturb other programs.
+            os.system('/usr/bin/ionice -c 3 -p %d' % os.getpid())
 
         # Start the live filesystem watcher.
         if enable_watcher:
-- 
GitLab