()
| 324 | read_error = [None] # Mutable container for thread error propagation |
| 325 | |
| 326 | def _producer(): |
| 327 | try: |
| 328 | with open(file_path, 'rb') as f: |
| 329 | while True: |
| 330 | chunk = f.read(buffer_size) |
| 331 | if not chunk: |
| 332 | break |
| 333 | chunk_queue.put(chunk) |
| 334 | except Exception as e: |
| 335 | read_error[0] = e |
| 336 | finally: |
| 337 | chunk_queue.put(None) # Sentinel to signal EOF |
| 338 | |
| 339 | reader_thread = threading.Thread(target=_producer, daemon=True) |
| 340 | reader_thread.start() |