code: def handle_sample(
      sample, dest_ix, field_names, metadata, allocator, fields
  ):
      # We should only have to retry at least one
      for i in range(2):
          try:
              allocator.set_current_sample(dest_ix)
              # We extract the sample in question from the dataset
              # We write each field individually to the metadata region
              for field_name, field, field_value in zip(
                  field_names, fields.values(), sample
              ):
                  destination = metadata[field_name][
                      dest_ix : dest_ix + 1
                  ]
                  field.encode(
                      destination, field_value, allocator.malloc
                  )
              # We managed to write all the data without reaching
              # the end of the page so we stop retrying
              break
          # If we couldn't fit this sample in the previous page we retry once from a fresh page
          except MemoryError:
              # We raise the error if it happens on the second try
              if i == 1:
                  raise
  
imports: from functools import partial
  from typing import Callable, List, Mapping
  from os import SEEK_END, path
  import numpy
  from time import sleep
  import ctypes
  from multiprocessing import shared_memory, cpu_count, Queue, Process, Value
  from tqdm import tqdm
  from tqdm.contrib.concurrent import thread_map
  from .utils import chunks, is_power_of_2
  from .fields.base import Field
  from .memory_allocator import MemoryAllocator
  from .types import TYPE_ID_HANDLER, get_metadata_type, HeaderType, FieldDescType, CURRENT_VERSION, ALLOC_TABLE_TYPE
label_desc: Use image node_id 3 for calling a global function with example usage: handle_sample(sample, dest_ix, field_names, metadata, allocator, fields) without return types