(root)/
Python-3.11.7/
Lib/
test/
test_wait4.py
       1  """This test checks for correct wait4() behavior.
       2  """
       3  
       4  import os
       5  import sys
       6  import unittest
       7  from test.fork_wait import ForkWait
       8  from test import support
       9  
      10  # If either of these do not exist, skip this test.
      11  if not support.has_fork_support:
      12      raise unittest.SkipTest("requires working os.fork()")
      13  
      14  support.get_attribute(os, 'wait4')
      15  
      16  
      17  class ESC[4;38;5;81mWait4Test(ESC[4;38;5;149mForkWait):
      18      def wait_impl(self, cpid, *, exitcode):
      19          option = os.WNOHANG
      20          if sys.platform.startswith('aix'):
      21              # Issue #11185: wait4 is broken on AIX and will always return 0
      22              # with WNOHANG.
      23              option = 0
      24          for _ in support.sleeping_retry(support.SHORT_TIMEOUT, error=False):
      25              # wait4() shouldn't hang, but some of the buildbots seem to hang
      26              # in the forking tests.  This is an attempt to fix the problem.
      27              spid, status, rusage = os.wait4(cpid, option)
      28              if spid == cpid:
      29                  break
      30          self.assertEqual(spid, cpid)
      31          self.assertEqual(os.waitstatus_to_exitcode(status), exitcode)
      32          self.assertTrue(rusage)
      33  
      34  def tearDownModule():
      35      support.reap_children()
      36  
      37  if __name__ == "__main__":
      38      unittest.main()