Database Reference
In-Depth Information
return self
def __exit__(self, type, value, traceback):
if self.output_file:
self.output_file.close()
self.output_file = None
def make_output_dir(self):
'''Creates an output directory for the downloaded
results.'''
output_dir = os.path.dirname(self.output_file_name)
if os.path.exists(output_dir) and
os.path.isdir(output_dir):
# Nothing to do.
return
os.makedirs(output_dir)
def handle_rows(self, rows):
if self.output_file is None:
self.__enter()
self.output_file.write(json.dumps(rows, indent=2))
class TableReadThread (threading.Thread):
'''Thread that reads from a table and writes it to a
file.'''
def __init__(self, table_reader, output_file_name,
thread_id='thread'):
threading.Thread.__init__(self)
self.table_reader = table_reader
self.output_file_name = output_file_name
self.thread_id = thread_id
def run(self):
print 'Reading %s' % (self.thread_id,)
with FileResultHandler(self.output_file_name) as
Search WWH ::




Custom Search