def read_files_worker(self, directory, queue):
""" Read all files in a directory and output to the queue. First line
of every file should contain the index. Worker separates first line
and parses to dict. Tuple of index and text is added to queue.
:directory: Source directory containing files
:queue: Queue to add the tuples to
"""
for file in os.scandir(directory):
if file.is_file():
with open(file.path, 'r', errors='replace') as f:
text = f.readlines()
try:
index = literal_eval(text.pop(0).strip())
queue.put((index, '\n'.join(text)), block=True)
except IndexError:
LOGGER.error('File {0} is not classifyable'
.format(file.path))
LOGGER.info('File reading worker done.')
评论列表
文章目录