chiark / gitweb /
flush debugging output before sleeping
authorIan Jackson <ian@liberator.(none)>
Sun, 17 May 2009 12:00:28 +0000 (13:00 +0100)
committerIan Jackson <ian@liberator.(none)>
Sun, 17 May 2009 12:00:28 +0000 (13:00 +0100)
yoweb-scrape

index 29af391..3c42f7e 100755 (executable)
@@ -41,6 +41,11 @@ def debug(m):
        if opts.debug > 0:
                print >>opts.debug_file, m
 
+def sleep(seconds):
+       if opts.debug > 0:
+               opts.debug_file.flush()
+       time.sleep(seconds)
+
 def format_time_interval(ti):
        if ti < 120: return '%d:%02d' % (ti / 60, ti % 60)
        if ti < 7200: return '%2dm' % (ti / 60)
@@ -103,7 +108,7 @@ class Fetcher:
                need_wait = self.need_wait(now)
                if need_wait > 0:
                        debug('Fetcher   wait %d' % need_wait)
-                       time.sleep(need_wait)
+                       sleep(need_wait)
 
        def fetch(self, url, max_age):
                debug('Fetcher fetch %s' % url)
@@ -803,7 +808,7 @@ def do_track_chat_log(args, bu):
                track.catchup()
                if track.changed():
                        print track
-               time.sleep(1)
+               sleep(1)
 
 #----- ship management aid -----
 
@@ -914,7 +919,7 @@ def do_ship_aid(args, bu):
                s += tbl.results()
 
                displayer.show(s)
-               time.sleep(1)
+               sleep(1)
                rotate_nya = rotate_nya[1:3] + rotate_nya[0]
 
 #---------- main program ----------