<!--- Verify first that your issue is not already reported on GitHub -->
<!--- Also test if the latest release and devel branch are affected too -->
<!--- Complete *all* sections as described, this form is processed automatically -->

##### SUMMARY
The `wait_for` integration test when run on macOS hosts in combination with some other tests results in a stack trace due to a zombie process. This appears in the `devel` nightlihtlies and occasionally in PRs. I am unable to duplicate this issue when running only the `wait_for` test, so it seems to be a test interaction issue. [Example test failure](https://app.shippable.com/github/ansible/ansible/runs/175420/17/tests).


##### ISSUE TYPE
- Bug Report

##### COMPONENT NAME
<!--- Write the short name of the module, plugin, task or feature below, use your best guess if unsure -->
`test/integration/targets/wait_for`
##### ANSIBLE VERSION
<!--- Paste verbatim output from "ansible --version" between quotes -->
```paste below
devel
```

##### CONFIGURATION
<!--- Paste verbatim output from "ansible-config dump --only-changed" between quotes -->
Shippable

##### OS / ENVIRONMENT
<!--- Provide all relevant information below, e.g. target OS versions, network device firmware, etc. -->
Shippable

##### STEPS TO REPRODUCE
<!--- Describe exactly how to reproduce the problem, using a minimal test-case -->
Run the nightly integration test.

<!--- HINT: You can paste gist.github.com links for larger files -->

##### EXPECTED RESULTS
<!--- Describe what you expected to happen when running the steps above -->
Tests pass.

##### ACTUAL RESULTS
<!--- Describe what actually happened. If possible run with extra verbosity (-vvvv) -->
Test fails with stack trace
<!--- Paste verbatim command output between quotes -->
```paste below
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/psutil/_psosx.py", line 363, in catch_zombie
    yield
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/psutil/_psosx.py", line 532, in connections
    rawlist = cext.proc_connections(self.pid, families, types)
ProcessLookupError: [Errno 3] No such process (originated from proc_pidinfo())

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/var/root/.ansible/tmp/ansible-tmp-1603438181.978554-24193-108782891618547/AnsiballZ_wait_for.py", line 140, in <module>
    _ansiballz_main()
  File "/var/root/.ansible/tmp/ansible-tmp-1603438181.978554-24193-108782891618547/AnsiballZ_wait_for.py", line 132, in _ansiballz_main
    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)
  File "/var/root/.ansible/tmp/ansible-tmp-1603438181.978554-24193-108782891618547/AnsiballZ_wait_for.py", line 81, in invoke_module
    runpy.run_module(mod_name='ansible.modules.wait_for', init_globals=None, run_name='__main__', alter_sys=True)
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/runpy.py", line 207, in run_module
    return _run_module_code(code, init_globals, run_name, mod_spec)
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/runpy.py", line 97, in _run_module_code
    _run_code(code, mod_globals, init_globals,
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "/tmp/ansible_wait_for_payload_dp2d351v/ansible_wait_for_payload.zip/ansible/modules/wait_for.py", line 667, in <module>
  File "/tmp/ansible_wait_for_payload_dp2d351v/ansible_wait_for_payload.zip/ansible/modules/wait_for.py", line 651, in main
  File "/tmp/ansible_wait_for_payload_dp2d351v/ansible_wait_for_payload.zip/ansible/modules/wait_for.py", line 295, in get_active_connections_count
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/psutil/__init__.py", line 1182, in connections
    return self._proc.connections(kind)
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/psutil/_psosx.py", line 342, in wrapper
    return fun(self, *args, **kwargs)
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/psutil/_psosx.py", line 532, in connections
    rawlist = cext.proc_connections(self.pid, families, types)
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/contextlib.py", line 131, in __exit__
    self.gen.throw(type, value, traceback)
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/psutil/_psosx.py", line 374, in catch_zombie
    raise ZombieProcess(proc.pid, proc._name, proc._ppid)
psutil.ZombieProcess: psutil.ZombieProcess process still exists but it's a zombie (pid=23005)
```

from __future__ import absolute_import, division, print_function
__metaclass__ = type
DOCUMENTATION = r'''
---
module: wait_for
short_description: Waits for a condition before continuing
description:
     - You can wait for a set amount of time C(timeout), this is the default if nothing is specified or just C(timeout) is specified.
       This does not produce an error.
     - Waiting for a port to become available is useful for when services are not immediately available after their init scripts return
       which is true of certain Java application servers.
     - It is also useful when starting guests with the M(community.libvirt.virt) module and needing to pause until they are ready.
     - This module can also be used to wait for a regex match a string to be present in a file.
     - In Ansible 1.6 and later, this module can also be used to wait for a file to be available or
       absent on the filesystem.
     - In Ansible 1.8 and later, this module can also be used to wait for active connections to be closed before continuing, useful if a node
       is being rotated out of a load balancer pool.
     - For Windows targets, use the M(ansible.windows.win_wait_for) module instead.
version_added: "0.7"
options:
  host:
    description:
      - A resolvable hostname or IP address to wait for.
    type: str
    default: 127.0.0.1
  timeout:
    description:
      - Maximum number of seconds to wait for, when used with another condition it will force an error.