Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def run(self):
if self.stdin_fd != -1:
sys.stdin.close()
sys.stdin = os.fdopen(self.stdin_fd)
try:
with xopen(self.file, 'rb') as f:
if self.file2:
with xopen(self.file2, 'rb') as f2:
for chunk_index, (chunk1, chunk2) in enumerate(
dnaio.read_paired_chunks(f, f2, self.buffer_size)):
self.send_to_worker(chunk_index, chunk1, chunk2)
else:
for chunk_index, chunk in enumerate(dnaio.read_chunks(f, self.buffer_size)):
self.send_to_worker(chunk_index, chunk)
# Send poison pills to all workers
for _ in range(len(self.connections)):
worker_index = self.queue.get()
self.connections[worker_index].send(-1)
except Exception as e:
# TODO better send this to a common "something went wrong" Queue
for connection in self.connections:
connection.send(-2)
connection.send((e, traceback.format_exc()))