code: def _lock(self, lock_func, lock_name):
      self.addCleanup(os_helper.unlink, os_helper.TESTFN)
      code = "\n".join(
          (
              "import fcntl, time",
              "with open('%s', 'wb') as f:" % os_helper.TESTFN,
              "   fcntl.%s(f, fcntl.LOCK_EX)" % lock_name,
              "   time.sleep(%s)" % self.sleep_time,
          )
      )
      start_time = time.monotonic()
      proc = self.subprocess(code)
      with kill_on_error(proc):
          with open(os_helper.TESTFN, "wb") as f:
              # synchronize the subprocess
              start_time = time.monotonic()
              for _ in support.sleeping_retry(
                  support.LONG_TIMEOUT, error=False
              ):
                  try:
                      lock_func(f, fcntl.LOCK_EX | fcntl.LOCK_NB)
                      lock_func(f, fcntl.LOCK_UN)
                  except BlockingIOError:
                      break
              else:
                  dt = time.monotonic() - start_time
                  raise Exception(
                      "failed to sync child in %.1f sec" % dt
                  )
  
              # the child locked the file just a moment ago for 'sleep_time' seconds
              # that means that the lock below will block for 'sleep_time' minus some
              # potential context switch delay
              lock_func(f, fcntl.LOCK_EX)
              dt = time.monotonic() - start_time
              self.stop_alarm()
              self.check_elapsed_time(dt)
          proc.wait()
  
imports: import contextlib
  import faulthandler
  import fcntl
  import os
  import platform
  import select
  import signal
  import socket
  import subprocess
  import sys
  import time
  import unittest
  from test import support
  from test.support import os_helper
  from test.support import socket_helper
label_desc: Use image node_id 1 for calling the FNTLEINTRTest obj's underlying member method code with example usage: obj._lock(lock_func, lock_name) without return types