MCPcopy Create free account
hub / github.com/Oneflow-Inc/oneflow / _worker_loop

Function _worker_loop

python/oneflow/utils/data/_utils/worker.py:235–377  ·  view source on GitHub ↗
(
    dataset_kind,
    dataset,
    index_queue,
    data_queue,
    done_event,
    auto_collation,
    collate_fn,
    drop_last,
    base_seed,
    init_fn,
    worker_id,
    num_workers,
    persistent_workers,
)

Source from the content-addressed store, hash-verified

233
234
235def _worker_loop(
236 dataset_kind,
237 dataset,
238 index_queue,
239 data_queue,
240 done_event,
241 auto_collation,
242 collate_fn,
243 drop_last,
244 base_seed,
245 init_fn,
246 worker_id,
247 num_workers,
248 persistent_workers,
249):
250 # See NOTE [ Data Loader Multiprocessing Shutdown Logic ] for details on the
251 # logic of this function.
252 try:
253
254 def cleanup_shm_at_exit(num, frame):
255 unlink_all_shared_memory()
256 # Use os._exit() to handle the exit of the subprocess to avoid share memory leaks
257 # caused by the subprocess continuing for a period of time after the parent process ends.
258 os._exit(0)
259
260 _prctl_pr_set_pdeathsig(signal.SIGINT)
261
262 # Initialize C side signal handlers for SIGBUS and SIGSEGV. Python signal
263 # module's handlers are executed after Python returns from C low-level
264 # handlers, likely when the same fatal signal had already happened
265 # again.
266 # https://docs.python.org/3/library/signal.html#execution-of-python-signal-handlers
267 signal_handling._set_worker_signal_handlers()
268 signal.signal(signal.SIGTERM, cleanup_shm_at_exit)
269 signal.signal(signal.SIGINT, cleanup_shm_at_exit)
270 flow.set_num_threads(1)
271 seed = base_seed + worker_id
272 random.seed(seed)
273 flow.manual_seed(seed)
274 if HAS_NUMPY:
275 np_seed = _generate_state(base_seed, worker_id)
276 import numpy as np
277
278 np.random.seed(np_seed)
279
280 global _worker_info
281 _worker_info = WorkerInfo(
282 id=worker_id, num_workers=num_workers, seed=seed, dataset=dataset
283 )
284
285 from oneflow.utils.data import _DatasetKind
286
287 init_exception = None
288
289 try:
290 if init_fn is not None:
291 init_fn(worker_id)
292

Callers

nothing calls this directly

Calls 13

is_aliveMethod · 0.95
ExceptionWrapperClass · 0.90
unlink_all_shared_memoryFunction · 0.90
_generate_stateFunction · 0.85
WorkerInfoClass · 0.85
ManagerWatchdogClass · 0.85
create_fetcherMethod · 0.80
seedMethod · 0.45
formatMethod · 0.45
getMethod · 0.45
fetchMethod · 0.45

Tested by

no test coverage detected