(dataset, index_queue, data_queue, collate_fn, seed, init_fn, worker_id)
| 35 | |
| 36 | |
| 37 | def _worker_loop(dataset, index_queue, data_queue, collate_fn, seed, init_fn, worker_id): |
| 38 | global _use_shared_memory |
| 39 | _use_shared_memory = True |
| 40 | |
| 41 | # Intialize C side signal handlers for SIGBUS and SIGSEGV. Python signal |
| 42 | # module's handlers are executed after Python returns from C low-level |
| 43 | # handlers, likely when the same fatal signal happened again already. |
| 44 | # https://docs.python.org/3/library/signal.html Sec. 18.8.1.1 |
| 45 | _set_worker_signal_handlers() |
| 46 | |
| 47 | torch.set_num_threads(1) |
| 48 | torch.manual_seed(seed) |
| 49 | np.random.seed(seed) |
| 50 | |
| 51 | if init_fn is not None: |
| 52 | init_fn(worker_id) |
| 53 | |
| 54 | while True: |
| 55 | r = index_queue.get() |
| 56 | if r is None: |
| 57 | break |
| 58 | idx, batch_indices = r |
| 59 | try: |
| 60 | samples = collate_fn([dataset[i] for i in batch_indices]) |
| 61 | except Exception: |
| 62 | data_queue.put((idx, ExceptionWrapper(sys.exc_info()))) |
| 63 | else: |
| 64 | data_queue.put((idx, samples)) |
| 65 | |
| 66 | |
| 67 | def _worker_manager_loop(in_queue, out_queue, done_event, pin_memory, device_id): |
nothing calls this directly
no test coverage detected