1 r""""Contains definitions of the methods used by the _DataLoaderIter workers. 3 These **needs** to be in global scope since Py2 doesn't support serializing 12 from .
import collate, signal_handling, MP_STATUS_CHECK_INTERVAL, \
13 ExceptionWrapper, IS_WINDOWS
17 from ctypes.wintypes
import DWORD, BOOL, HANDLE
26 self.
kernel32 = ctypes.WinDLL(
'kernel32', use_last_error=
True)
27 self.kernel32.OpenProcess.argtypes = (DWORD, BOOL, DWORD)
28 self.kernel32.OpenProcess.restype = HANDLE
29 self.kernel32.WaitForSingleObject.argtypes = (HANDLE, DWORD)
30 self.kernel32.WaitForSingleObject.restype = DWORD
33 SYNCHRONIZE = 0x00100000
37 raise ctypes.WinError(ctypes.get_last_error())
58 def _worker_loop(dataset, index_queue, data_queue, done_event, collate_fn, seed, init_fn, worker_id):
63 collate._use_shared_memory =
True 70 signal_handling._set_worker_signal_handlers()
72 torch.set_num_threads(1)
74 torch.manual_seed(seed)
76 data_queue.cancel_join_thread()
78 if init_fn
is not None:
83 while watchdog.is_alive():
85 r = index_queue.get(timeout=MP_STATUS_CHECK_INTERVAL)
90 assert done_event.is_set()
92 elif done_event.is_set():
97 idx, batch_indices = r
99 samples = collate_fn([dataset[i]
for i
in batch_indices])
105 data_queue.put((idx, samples))
107 except KeyboardInterrupt: