class_docstr: Initializes structures necessary for a worker process to receive,
  compute and send back tasks.
class_docstr_tok: ["Initializes","structures","necessary","for","a","worker","process","to","receive",",","compute","and","send","back","tasks","."]
code: def __init__(self, worker_args: WorkerArgs):
      self.worker_id = worker_args.worker_id
      self.callbacks = self._init_callbacks(
          worker_args.source_descs, worker_args.callback_pickler
      )
      self.result_queue = worker_args.result_queue
      self.general_task_queue = worker_args.general_task_queue
      self.dedicated_task_queue = worker_args.dedicated_task_queue
      shm_chunks = worker_args.shm_chunks
      if worker_args.start_method != "fork":
          setup_socket = worker_args.setup_socket
          # NOTE when making any changes here, make sure to reflect them in the main process,
          # so that it sends handles to objects in the same order they are set to objects here
          self._recv_queue_handles(setup_socket)
          for shm_chunk in shm_chunks:
              shm_chunk.open_shm(reduction.recv_handle(setup_socket))
          setup_socket.shutdown(socket.SHUT_RDWR)
          setup_socket.close()
      self.shm_chunks = {
          shm_chunk.shm_chunk_id: shm_chunk for shm_chunk in shm_chunks
      }
      self.task_receiver = None
      self.batch_dispatcher = None
      try:
          self.task_receiver = self._init_task_receiver()
          self.batch_dispatcher = SharedBatchDispatcher(
              worker_args.worker_id,
              worker_args.result_queue,
              self.task_receiver.get_recv_queues(),
          )
      except:  # noqa E722
          self.close()
          raise
      # let the main process know that the worker started and shared resources setup is done
      worker_args.result_queue.put(
          [ShmMessageDesc(self.worker_id, 0, 0, 0, 0)]
      )
  
imports: from typing import List, Optional, Tuple
  import threading
  import traceback
  import socket
  from collections import deque
  from multiprocessing import reduction
  from nvidia.dali._utils.external_source_impl import SourceKind, _is_generator_function
  from nvidia.dali._multiproc.shared_batch import SharedBatchWriter, SharedBatchMeta, BufShmChunk, assert_valid_data_type, read_shm_message, write_shm_message
  from nvidia.dali._multiproc.messages import CompletedTask, WorkerArgs, ShmMessageDesc, ScheduledTask
  from nvidia.dali._multiproc.shared_queue import Dispatcher
label_desc: Use image node_id 1 to create a new WorkerContext object  with example: obj = WorkerContext(worker_args)