Revision: 3950
Author: valhallasw
Date: 2007-08-02 12:11:29 +0000 (Thu, 02 Aug 2007)
Log Message:
-----------
bugfix: the output buffer now actually gets cleared. Changed break to return in the
put_async waiting routine ^c-handler.
Modified Paths:
--------------
trunk/pywikipedia/wikipedia.py
Modified: trunk/pywikipedia/wikipedia.py
===================================================================
--- trunk/pywikipedia/wikipedia.py 2007-08-02 10:26:31 UTC (rev 3949)
+++ trunk/pywikipedia/wikipedia.py 2007-08-02 12:11:29 UTC (rev 3950)
@@ -4491,12 +4491,20 @@
logfile.write(text + '\n')
logfile.flush()
if input_lock.locked():
- output_cache.append(((text,), {'colors': colors, 'newline':
newline, 'toStdout': toStdout}))
+ cache_output(text, colors = colors, newline = newline, toStdout = toStdout)
else:
ui.output(text, colors = colors, newline = newline, toStdout = toStdout)
finally:
output_lock.release()
+def cache_output(*args, **kwargs):
+ output_cache.append((args, kwargs))
+
+def flush_output_cache():
+ while(output_cache):
+ (args, kwargs) = output_cache.pop(0)
+ ui.output(*args, **kwargs)
+
def input(question, colors = None, password = False):
"""
Asks the user a question, then returns the user's answer.
@@ -4513,15 +4521,12 @@
input_lock.acquire()
try:
data = ui.input(question, colors, password)
- finally:
- for output in output_cache:
- ui.output(*output[0], **output[1])
+ finally:
+ flush_output_cache()
input_lock.release()
- for output in output_cache: #for output added between the start of the for loop and
the lock release
- ui.output(*output[0], **output[1])
-
+
return data
-
+
def inputChoice(question, answers, hotkeys, default = None):
"""
Asks the user a question and offers several options, then returns the
@@ -4543,12 +4548,9 @@
try:
data = ui.inputChoice(question, answers, hotkeys, default).lower()
finally:
- for output in output_cache:
- ui.output(*output[0], **output[1])
+ flush_output_cache()
input_lock.release()
- for output in output_cache: #for output added between the start of the for loop and
the lock release
- ui.output(*output[0], **output[1])
-
+
return data
def showHelp(moduleName = None):
@@ -4646,7 +4648,7 @@
% (page_put_queue.qsize(),
datetime.timedelta(seconds=(page_put_queue.qsize()) * config.put_throttle)),
['yes', 'no'], ['y', 'N'],
'N')
if answer in ['y', 'Y']:
- break
+ return
import atexit
atexit.register(_flush)