Repository: numba/numba

Issue:
objmode() triggers fork()
## Reporting a bug

<!--

Before submitting a bug report please ensure that you can check off these boxes:

-->

- [x] I have tried using the latest released version of Numba (most recent is
 visible in the change log (https://github.com/numba/numba/blob/main/CHANGE_LOG).
- [x] I have included a self contained code sample to reproduce the problem.
  i.e. it's possible to run as 'python bug.py'.

<!--

Please include details of the bug here, including, if applicable, what you
expected to happen!

-->

It seems that using [`with numba.objmode()`](https://numba.readthedocs.io/en/stable/user/withobjmode.html) is triggering a call to `fork()` somewhere. In an MPI context, this can be problematic – Open MPI is complaining about this with a message of the following form:

>     --------------------------------------------------------------------------
>     A process has executed an operation involving a call to the
>     "fork()" system call to create a child process.  Open MPI is currently
>     operating in a condition that could result in memory corruption or
>     other system errors; your job may hang, crash, or produce silent
>     data corruption.  The use of fork() (or system() or other calls that
>     create child processes) is strongly discouraged.
>     
>     The process that invoked fork was:
>     
>       Local host:          [[53156,1],2] (PID 26851)
>     
>     If you are *absolutely sure* that your application will successfully
>     and correctly survive a call to fork(), you may disable this warning
>     by setting the mpi_warn_on_fork MCA parameter to 0.
>     --------------------------------------------------------------------------

Using the same code, but omitting `with numba.objmode()`, Open MPI doesn’t complain. As far as I can remember, this issue only started to appear recently, so there seems to have been a change in the implementation causing this? If there is some way to stop `objmode()` from triggering a `fork()`, that would be great.

<details>
  <summary>(Trivial) code sample</summary>

```
import numba
from mpi4py import MPI

mpi_comm = MPI.COMM_WORLD
mpi_rank = mpi_comm.Get_rank()

@numba.njit
def f():
    with numba.objmode():
        print(mpi_rank)

f()
```
</details>

<details>
  <summary>Running the sample and output</summary>

>     $ mpiexec -n 3 python3 test.py
>     --------------------------------------------------------------------------
>     A process has executed an operation involving a call to the
>     "fork()" system call to create a child process.  Open MPI is currently
>     operating in a condition that could result in memory corruption or
>     other system errors; your job may hang, crash, or produce silent
>     data corruption.  The use of fork() (or system() or other calls that
>     create child processes) is strongly discouraged.
>     
>     The process that invoked fork was:
>     
>       Local host:          [[53156,1],2] (PID 26851)
>     
>     If you are *absolutely sure* that your application will successfully
>     and correctly survive a call to fork(), you may disable this warning
>     by setting the mpi_warn_on_fork MCA parameter to 0.
>     --------------------------------------------------------------------------
>     1
>     2
>     0
>     [host:26836] 2 more processes have sent help message help-opal-runtime.txt / opal_init:warn-fork
>     [host:26836] Set MCA parameter "orte_base_help_aggregate" to 0 to see all help / error messages
</details>



Discussion:
@Socob thank you for submitting this. I am having a little trouble reproducing this. Can you paste the output of `numba -s`?

Here is mine:

```
 zsh» numba -s
System info:
--------------------------------------------------------------------------------
__Time Stamp__
Report started (local time)                   : 2022-03-03 12:17:10.572351
UTC start time                                : 2022-03-03 11:17:10.572355
Running time (s)                              : 0.936455

__Hardware Information__
Machine                                       : x86_64
CPU Name                                      : skylake
CPU Count                                     : 8
Number of accessible CPUs                     : 8
List of accessible CPUs cores                 : 0-7
CFS Restrictions (CPUs worth of runtime)      : None

CPU Features                                  : 64bit adx aes avx avx2 bmi bmi2
                                                clflushopt cmov cx16 cx8 f16c fma
                                                fsgsbase fxsr invpcid lzcnt mmx
                                                movbe pclmul popcnt prfchw rdrnd
                                                rdseed sahf sgx sse sse2 sse3
                                                sse4.1 sse4.2 ssse3 xsave xsavec
                                                xsaveopt xsaves

Memory Total (MB)                             : 7847
Memory Available (MB)                         : 2770

__OS Information__
Platform Name                                 : Linux-5.4.0-99-generic-x86_64-with-glibc2.17
Platform Release                              : 5.4.0-99-generic
OS Name                                       : Linux
OS Version                                    : #112-Ubuntu SMP Thu Feb 3 13:50:55 UTC 2022
OS Specific Version                           : ?
Libc Version                                  : glibc 2.31

__Python Information__
Python Compiler                               : GCC 7.5.0
Python Implementation                         : CPython
Python Version                                : 3.8.12
Python Locale                                 : en_US.UTF-8

__Numba Toolchain Versions__
Numba Version                                 : 0.56.0dev0+321.g59fa2e335b
llvmlite Version                              : 0.39.0dev0+42.gdf27949

__LLVM Information__
LLVM Version                                  : 11.1.0

__CUDA Information__
CUDA Device Initialized                       : False
CUDA Driver Version                           : ?
CUDA Runtime Version                          : ?
CUDA NVIDIA Bindings Available                : ?
CUDA NVIDIA Bindings In Use                   : ?
CUDA Detect Output:
None
CUDA Libraries Test Output:
None

__SVML Information__
SVML State, config.USING_SVML                 : False
SVML Library Loaded                           : False
llvmlite Using SVML Patched LLVM              : True
SVML Operational                              : False

__Threading Layer Information__
TBB Threading Layer Available                 : False
+--> Disabled due to Unknown import problem.
OpenMP Threading Layer Available              : True
+-->Vendor: GNU
Workqueue Threading Layer Available           : True
+-->Workqueue imported successfully.

__Numba Environment Variable Information__
None found.

__Conda Information__
Conda Build                                   : not installed
Conda Env                                     : 4.11.0
Conda Platform                                : linux-64
Conda Python Version                          : 3.7.11.final.0
Conda Root Writable                           : True

__Installed Packages__
_libgcc_mutex             0.1                        main    defaults
_openmp_mutex             4.5                       1_gnu    defaults
_sysroot_linux-64_curr_repodata_hack 3                   haa98f57_10    defaults
backcall                  0.2.0              pyhd3eb1b0_0    defaults
binutils_impl_linux-64    2.35.1               h27ae35d_9    defaults
binutils_linux-64         2.35.1              h454624a_30    defaults
blas                      1.0                         mkl    defaults
ca-certificates           2022.2.1             h06a4308_0    defaults
certifi                   2021.10.8        py38h06a4308_2    defaults
cffi                      1.15.0           py38hd667e15_1    defaults
cfgv                      3.3.1                    pypi_0    pypi
charset-normalizer        2.0.12                   pypi_0    pypi
colorama                  0.4.4              pyhd3eb1b0_0    defaults
cryptography              36.0.1                   pypi_0    pypi
decorator                 5.1.1              pyhd3eb1b0_0    defaults
distlib                   0.3.4                    pypi_0    pypi
docopt                    0.6.2                    pypi_0    pypi
filelock                  3.6.0                    pypi_0    pypi
flake8                    4.0.1              pyhd3eb1b0_0    defaults
gcc_impl_linux-64         9.3.0               h6df7d76_17    defaults
gcc_linux-64              9.3.0               h1ee779e_30    defaults
git-spindle               4.0.1                    pypi_0    pypi
github3-py                3.2.0                    pypi_0    pypi
gxx_impl_linux-64         9.3.0               hbdd7822_17    defaults
gxx_linux-64              9.3.0               h7e70986_30    defaults
identify                  2.4.11                   pypi_0    pypi
idna                      3.3                      pypi_0    pypi
importlib-metadata        4.8.2            py38h06a4308_0    defaults
importlib_metadata        4.8.2                hd3eb1b0_0    defaults
intel-openmp              2021.4.0          h06a4308_3561    defaults
ipdb                      0.13.9             pyhd8ed1ab_0    conda-forge
ipython                   7.31.1           py38h06a4308_0    defaults
jedi                      0.18.1           py38h06a4308_1    defaults
jinja2                    3.0.2              pyhd3eb1b0_0    defaults
kernel-headers_linux-64   3.10.0              h57e8cba_10    defaults
ld_impl_linux-64          2.35.1               h7274673_9    defaults
libffi                    3.3                  he6710b0_2    defaults
libgcc-devel_linux-64     9.3.0               hb95220a_17    defaults
libgcc-ng                 9.3.0               h5101ec6_17    defaults
libgfortran-ng            7.5.0               ha8ba4b0_17    defaults
libgfortran4              7.5.0               ha8ba4b0_17    defaults
libgomp                   9.3.0               h5101ec6_17    defaults
libstdcxx-devel_linux-64  9.3.0               hf0c5c8d_17    defaults
libstdcxx-ng              9.3.0               hd4cf53a_17    defaults
llvmlite                  0.39.0dev0      py38he1b5a44_42    numba/label/dev
markupsafe                2.0.1            py38h27cfd23_0    defaults
matplotlib-inline         0.1.2              pyhd3eb1b0_2    defaults
mccabe                    0.6.1                    py38_1    defaults
mkl                       2021.4.0           h06a4308_640    defaults
mkl-service               2.4.0            py38h7f8727e_0    defaults
mkl_fft                   1.3.1            py38hd3c417c_0    defaults
mkl_random                1.2.2            py38h51133e4_0    defaults
mpi                       1.0                       mpich    defaults
mpi4py                    3.0.3            py38h028fd6f_0    defaults
mpich                     3.3.2                hc856adb_0    defaults
ncurses                   6.3                  h7f8727e_2    defaults
nodeenv                   1.6.0                    pypi_0    pypi
numba                     0.56.0.dev0+321.g59fa2e335b           dev_0    <develop>
numpy                     1.21.2           py38h20f2e39_0    defaults
numpy-base                1.21.2           py38h79a1101_0    defaults
openssl                   1.1.1m               h7f8727e_0    defaults
parso                     0.8.3              pyhd3eb1b0_0    defaults
pexpect                   4.8.0              pyhd3eb1b0_3    defaults
pickleshare               0.7.5           pyhd3eb1b0_1003    defaults
pip                       21.2.4           py38h06a4308_0    defaults
platformdirs              2.5.1                    pypi_0    pypi
pre-commit                2.17.0                   pypi_0    pypi
prompt-toolkit            3.0.20             pyhd3eb1b0_0    defaults
ptyprocess                0.7.0              pyhd3eb1b0_2    defaults
pycodestyle               2.7.0              pyhd3eb1b0_0    defaults
pycparser                 2.21               pyhd3eb1b0_0    defaults
pyflakes                  2.3.1              pyhd3eb1b0_0    defaults
pygments                  2.11.2             pyhd3eb1b0_0    defaults
pyjwt                     2.3.0                    pypi_0    pypi
python                    3.8.12               h12debd9_0    defaults
python-dateutil           2.8.2                    pypi_0    pypi
python-gitlab             3.2.0                    pypi_0    pypi
python_abi                3.8                      2_cp38    conda-forge
pyyaml                    6.0              py38h7f8727e_1    defaults
readline                  8.1.2                h7f8727e_1    defaults
requests                  2.27.1                   pypi_0    pypi
requests-toolbelt         0.9.1                    pypi_0    pypi
scipy                     1.7.3            py38hc147768_0    defaults
setuptools                58.0.4           py38h06a4308_0    defaults
six                       1.16.0             pyhd3eb1b0_1    defaults
sqlite                    3.37.2               hc218d9a_0    defaults
sysroot_linux-64          2.17                h57e8cba_10    defaults
tk                        8.6.11               h1ccaba5_0    defaults
toml                      0.10.2                   pypi_0    pypi
traitlets                 5.1.1              pyhd3eb1b0_0    defaults
uritemplate               4.1.1                    pypi_0    pypi
urllib3                   1.26.8                   pypi_0    pypi
virtualenv                20.13.2                  pypi_0    pypi
wcwidth                   0.2.5              pyhd3eb1b0_0    defaults
wheel                     0.37.1             pyhd3eb1b0_0    defaults
whelk                     3.0                      pypi_0    pypi
xz                        5.2.5                h7b6447c_0    defaults
yaml                      0.2.5                h7b6447c_0    defaults
zipp                      3.7.0              pyhd3eb1b0_0    defaults
zlib                      1.2.11               h7f8727e_4    defaults

No errors reported.


__Warning log__
Warning (cuda): CUDA driver library cannot be found or no CUDA enabled devices are present.
Exception class: <class 'numba.cuda.cudadrv.error.CudaSupportError'>
Warning (psutil): psutil cannot be imported. For more accuracy, consider installing it.
```

@esc Sorry for the delay. First of all, here is `numba -s` on the machine in question:

<details>
  <summary>numba -s</summary>

>     System info:
>     --------------------------------------------------------------------------------
>     __Time Stamp__
>     Report started (local time)                   : 2022-03-05 16:37:48.467491
>     UTC start time                                : 2022-03-05 15:37:48.467498
>     Running time (s)                              : 2.468318
> 
>     __Hardware Information__
>     Machine                                       : x86_64
>     CPU Name                                      : skylake-avx512
>     CPU Count                                     : 40
>     Number of accessible CPUs                     : 40
>     List of accessible CPUs cores                 : 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
>     CFS Restrictions (CPUs worth of runtime)      : None
> 
>     CPU Features                                  : 64bit adx aes avx avx2 avx512bw
>                                                     avx512cd avx512dq avx512f avx512vl
>                                                     bmi bmi2 clflushopt clwb cmov cx16
>                                                     cx8 f16c fma fsgsbase fxsr invpcid
>                                                     lzcnt mmx movbe pclmul pku popcnt
>                                                     prfchw rdrnd rdseed rtm sahf sse
>                                                     sse2 sse3 sse4.1 sse4.2 ssse3
>                                                     xsave xsavec xsaveopt xsaves
> 
>     Memory Total (MB)                             : 386358
>     Memory Available (MB)                         : 68253
> 
>     __OS Information__
>     Platform Name                                 : Linux-5.3.18-24.49-default-x86_64-with-glibc2.26
>     Platform Release                              : 5.3.18-24.49-default
>     OS Name                                       : Linux
>     OS Version                                    : #1 SMP Mon Feb 1 16:04:00 UTC 2021 (1e925eb)
>     OS Specific Version                           : ?
>     Libc Version                                  : glibc 2.26
> 
>     __Python Information__
>     Python Compiler                               : GCC 7.5.0
>     Python Implementation                         : CPython
>     Python Version                                : 3.9.7
>     Python Locale                                 : en_US.UTF-8
> 
>     __Numba Toolchain Versions__
>     Numba Version                                 : 0.55.1
>     llvmlite Version                              : 0.38.0
> 
>     __LLVM Information__
>     LLVM Version                                  : 11.1.0
> 
>     __CUDA Information__
>     CUDA Device Initialized                       : False
>     CUDA Driver Version                           : ?
>     CUDA Runtime Version                          : ?
>     CUDA NVIDIA Bindings Available                : ?
>     CUDA NVIDIA Bindings In Use                   : ?
>     CUDA Detect Output:
>     None
>     CUDA Libraries Test Output:
>     None
> 
>     __SVML Information__
>     SVML State, config.USING_SVML                 : False
>     SVML Library Loaded                           : False
>     llvmlite Using SVML Patched LLVM              : True
>     SVML Operational                              : False
> 
>     __Threading Layer Information__
>     TBB Threading Layer Available                 : True
>     +-->TBB imported successfully.
>     OpenMP Threading Layer Available              : True
>     +-->Vendor: GNU
>     Workqueue Threading Layer Available           : True
>     +-->Workqueue imported successfully.
> 
>     __Numba Environment Variable Information__
>     None found.
> 
>     __Conda Information__
>     Conda Build                                   : 3.21.5
>     Conda Env                                     : 4.10.3
>     Conda Platform                                : linux-64
>     Conda Python Version                          : 3.9.7.final.0
>     Conda Root Writable                           : False
> 
>     __Installed Packages__
>     _anaconda_depends         2021.11                  py39_0    <unknown>
>     _ipyw_jlab_nb_ext_conf    0.1.0            py39h06a4308_0  
>     _libgcc_mutex             0.1                 conda_forge    <unknown>
>     _openmp_mutex             4.5                       1_gnu    <unknown>
>     alabaster                 0.7.12             pyhd3eb1b0_0  
>     anaconda                  custom                   py39_1    <unknown>
>     anaconda-client           1.9.0            py39h06a4308_0  
>     anaconda-navigator        2.1.1                    py39_0  
>     anaconda-project          0.10.1             pyhd3eb1b0_0  
>     anyio                     2.2.0            py39h06a4308_1  
>     appdirs                   1.4.4              pyhd3eb1b0_0  
>     argh                      0.26.2           py39h06a4308_0  
>     argon2-cffi               20.1.0           py39h27cfd23_1  
>     arrow                     0.13.1           py39h06a4308_0  
>     asn1crypto                1.4.0                      py_0  
>     astroid                   2.6.6            py39h06a4308_0  
>     astropy                   4.3.1            py39h09021b7_0  
>     astunparse                1.6.3              pyhd8ed1ab_0    <unknown>
>     async_generator           1.10               pyhd3eb1b0_0  
>     atomicwrites              1.4.0                      py_0  
>     attrs                     21.2.0             pyhd3eb1b0_0  
>     autopep8                  1.5.7              pyhd3eb1b0_0  
>     babel                     2.9.1              pyhd3eb1b0_0  
>     backcall                  0.2.0              pyhd3eb1b0_0  
>     backports                 1.0                pyhd3eb1b0_2  
>     backports.functools_lru_cache 1.6.4              pyhd3eb1b0_0  
>     backports.shutil_get_terminal_size 1.0.0              pyhd3eb1b0_3  
>     backports.tempfile        1.0                pyhd3eb1b0_1  
>     backports.weakref         1.0.post1                  py_1  
>     basemap                   1.2.2            py39h5220be8_2    <unknown>
>     beautifulsoup4            4.10.0             pyh06a4308_0  
>     bhmm                      0.6.3           py39h16ac069_1004    <unknown>
>     binaryornot               0.4.4              pyhd3eb1b0_1  
>     biopython                 1.79             py39h3811e60_0    <unknown>
>     bitarray                  2.3.0            py39h7f8727e_1  
>     bkcharts                  0.2              py39h06a4308_0  
>     black                     19.10b0                    py_0  
>     blas                      1.0                         mkl  
>     bleach                    4.0.0              pyhd3eb1b0_0  
>     blosc                     1.21.0               h8c45485_0  
>     bokeh                     2.4.1            py39h06a4308_0  
>     boto                      2.49.0           py39h06a4308_0  
>     bottleneck                1.3.2            py39hdd57654_1  
>     brotli                    1.0.9                he6710b0_2  
>     brotlipy                  0.7.0           py39h27cfd23_1003  
>     brunsli                   0.1                  h2531618_0  
>     bzip2                     1.0.8                h7b6447c_0  
>     c-ares                    1.17.1               h27cfd23_0  
>     ca-certificates           2021.10.26           h06a4308_2  
>     cached-property           1.5.2                      py_0  
>     cairo                     1.16.0               hf32fb01_1  
>     certifi                   2021.10.8        py39h06a4308_0  
>     cffi                      1.14.6           py39h400218f_0  
>     cfitsio                   3.470                hf0d0db6_6  
>     cftime                    1.5.1.1          py39hce1f21e_0    <unknown>
>     chardet                   4.0.0           py39h06a4308_1003  
>     charls                    2.2.0                h2531618_0  
>     charset-normalizer        2.0.4              pyhd3eb1b0_0  
>     click                     8.0.3              pyhd3eb1b0_0  
>     cloudpickle               2.0.0              pyhd3eb1b0_0  
>     clyent                    1.2.2            py39h06a4308_1  
>     colorama                  0.4.4              pyhd3eb1b0_0  
>     commonmark                0.9.1                      py_0    <unknown>
>     conda                     4.10.3           py39h06a4308_0  
>     conda-build               3.21.5           py39h06a4308_0  
>     conda-content-trust       0.1.1              pyhd3eb1b0_0  
>     conda-env                 2.6.0                         1  
>     conda-pack                0.6.0              pyhd3eb1b0_0  
>     conda-package-handling    1.7.3            py39h27cfd23_1  
>     conda-repo-cli            1.0.4              pyhd3eb1b0_0  
>     conda-token               0.3.0              pyhd3eb1b0_0  
>     conda-verify              3.4.2                      py_1  
>     contextlib2               0.6.0.post1        pyhd3eb1b0_0  
>     cookiecutter              1.7.2              pyhd3eb1b0_0  
>     cryptography              3.4.8            py39hd23ed53_0  
>     curl                      7.78.0               h1ccaba5_0  
>     cycler                    0.10.0           py39h06a4308_0  
>     cython                    0.29.24          py39hdbfa776_0  
>     cytoolz                   0.11.0           py39h27cfd23_0  
>     dal                       2021.3.0           h06a4308_557  
>     dask                      2021.10.0          pyhd3eb1b0_0  
>     dask-core                 2021.10.0          pyhd3eb1b0_0  
>     dataclasses               0.8                pyh6d0b6a4_7  
>     dbus                      1.13.18              hb2f20db_0  
>     debugpy                   1.4.1            py39h295c915_0  
>     decorator                 5.1.0              pyhd3eb1b0_0  
>     deeptime                  0.2.9            py39hde0f152_0    <unknown>
>     defusedxml                0.7.1              pyhd3eb1b0_0  
>     diff-match-patch          20200713           pyhd3eb1b0_0  
>     dill                      0.3.4              pyhd8ed1ab_0    <unknown>
>     distributed               2021.10.0        py39h06a4308_0  
>     docutils                  0.17.1           py39h06a4308_1  
>     entrypoints               0.3              py39h06a4308_0  
>     et_xmlfile                1.1.0            py39h06a4308_0  
>     expat                     2.4.1                h2531618_2  
>     fastcache                 1.1.0            py39he8ac12f_0  
>     fftw                      3.3.8           nompi_hfc0cae8_1114    <unknown>
>     filelock                  3.3.1              pyhd3eb1b0_1  
>     flake8                    3.9.2              pyhd3eb1b0_0  
>     flask                     1.1.2              pyhd3eb1b0_0  
>     fontconfig                2.13.1               h6c09931_0  
>     fonttools                 4.25.0             pyhd3eb1b0_0  
>     freetype                  2.10.4               h5ab3b9f_0  
>     fribidi                   1.0.10               h7b6447c_0  
>     fsspec                    2021.8.1           pyhd3eb1b0_0  
>     future                    0.18.2           py39h06a4308_1  
>     geos                      3.8.1                he1b5a44_0    <unknown>
>     get_terminal_size         1.0.0                haa9412d_0  
>     gevent                    21.8.0           py39h7f8727e_1  
>     giflib                    5.2.1                h7b6447c_0  
>     gitdb                     4.0.9              pyhd8ed1ab_0    <unknown>
>     gitpython                 3.1.24             pyhd8ed1ab_0    <unknown>
>     glib                      2.69.1               h5202010_0  
>     glob2                     0.7                pyhd3eb1b0_0  
>     gmp                       6.2.1                h2531618_2  
>     gmpy2                     2.0.8            py39h8083e48_3  
>     graphite2                 1.3.14               h23475e2_0  
>     greenlet                  1.1.1            py39h295c915_0  
>     griddataformats           0.6.0              pyhd8ed1ab_0    <unknown>
>     gsd                       2.4.2            py39hce5d2b2_0    <unknown>
>     gst-plugins-base          1.14.0               h8213a91_2  
>     gstreamer                 1.14.0               h28cd5cc_2  
>     h5py                      3.3.0            py39h930cdd6_0  
>     harfbuzz                  2.8.1                h6f93f22_0  
>     hdf4                      4.2.13               h3ca952b_2    <unknown>
>     hdf5                      1.10.6               hb1b8bf9_0  
>     heapdict                  1.0.1              pyhd3eb1b0_0  
>     html5lib                  1.1                pyhd3eb1b0_0  
>     icu                       58.2                 he6710b0_3  
>     idna                      3.2                pyhd3eb1b0_0  
>     imagecodecs               2021.8.26        py39h4cda21f_0  
>     imageio                   2.9.0              pyhd3eb1b0_0  
>     imagesize                 1.2.0              pyhd3eb1b0_0  
>     importlib-metadata        4.8.1            py39h06a4308_0  
>     importlib_metadata        4.8.1                hd3eb1b0_0  
>     inflection                0.5.1            py39h06a4308_0  
>     iniconfig                 1.1.1              pyhd3eb1b0_0  
>     intel-openmp              2021.4.0          h06a4308_3561  
>     intervaltree              3.1.0              pyhd3eb1b0_0  
>     ipykernel                 6.4.1            py39h06a4308_1  
>     ipython                   7.29.0           py39hb070fc8_0  
>     ipython_genutils          0.2.0              pyhd3eb1b0_1  
>     ipywidgets                7.6.5              pyhd3eb1b0_1  
>     isort                     5.9.3              pyhd3eb1b0_0  
>     itsdangerous              2.0.1              pyhd3eb1b0_0  
>     jbig                      2.1                  hdba287a_0  
>     jdcal                     1.4.1              pyhd3eb1b0_0  
>     jedi                      0.18.0           py39h06a4308_1  
>     jeepney                   0.7.1              pyhd3eb1b0_0  
>     jinja2                    2.11.3             pyhd3eb1b0_0  
>     jinja2-time               0.2.0              pyhd3eb1b0_2  
>     joblib                    1.1.0              pyhd3eb1b0_0  
>     jpeg                      9d                   h7f8727e_0  
>     json5                     0.9.6              pyhd3eb1b0_0  
>     jsonschema                3.2.0              pyhd3eb1b0_2  
>     jupyter                   1.0.0            py39h06a4308_7  
>     jupyter-server-mathjax    0.2.3              pyhd8ed1ab_0    <unknown>
>     jupyter_client            6.1.12             pyhd3eb1b0_0  
>     jupyter_console           6.4.0              pyhd3eb1b0_0  
>     jupyter_core              4.8.1            py39h06a4308_0  
>     jupyter_server            1.4.1            py39h06a4308_0  
>     jupyterlab                3.2.1              pyhd3eb1b0_1  
>     jupyterlab_pygments       0.1.2                      py_0  
>     jupyterlab_server         2.8.2              pyhd3eb1b0_0  
>     jupyterlab_widgets        1.0.0              pyhd3eb1b0_1  
>     jxrlib                    1.1                  h7b6447c_2  
>     keyring                   23.1.0           py39h06a4308_0  
>     kiwisolver                1.3.1            py39h2531618_0  
>     krb5                      1.19.2               hac12032_0  
>     lazy-object-proxy         1.6.0            py39h27cfd23_0  
>     lcms2                     2.12                 h3be6417_0  
>     ld_impl_linux-64          2.35.1               h7274673_9  
>     lerc                      3.0                  h295c915_0  
>     libaec                    1.0.4                he6710b0_1  
>     libarchive                3.4.2                h62408e4_0  
>     libcurl                   7.78.0               h0b77cf5_0  
>     libdeflate                1.8                  h7f8727e_5  
>     libedit                   3.1.20210910         h7f8727e_0  
>     libev                     4.33                 h7f8727e_1  
>     libffi                    3.3                  he6710b0_2  
>     libgcc-ng                 11.2.0              h1d223b6_11    <unknown>
>     libgfortran-ng            7.5.0               ha8ba4b0_17  
>     libgfortran4              7.5.0               ha8ba4b0_17  
>     libgomp                   11.2.0              h1d223b6_11    <unknown>
>     liblief                   0.10.1               h2531618_1  
>     libllvm11                 11.1.0               h3826bc1_0  
>     libnetcdf                 4.6.1                h2053bdc_4    <unknown>
>     libnghttp2                1.41.0               hf8bcb03_2  
>     libpng                    1.6.37               hbc83047_0  
>     libsodium                 1.0.18               h7b6447c_0  
>     libspatialindex           1.9.3                h2531618_0  
>     libssh2                   1.9.0                h1ba5d50_1  
>     libstdcxx-ng              11.2.0              he4da1e4_11    <unknown>
>     libtiff                   4.2.0                h85742a9_0  
>     libtool                   2.4.6             h7b6447c_1005  
>     libuuid                   1.0.3                h7f8727e_2  
>     libuv                     1.40.0               h7b6447c_0  
>     libwebp                   1.2.0                h89dd481_0  
>     libwebp-base              1.2.0                h27cfd23_0  
>     libxcb                    1.14                 h7b6447c_0  
>     libxml2                   2.9.12               h03d6c58_0  
>     libxslt                   1.1.34               hc22bd24_0  
>     libzopfli                 1.0.3                he6710b0_0  
>     llvmlite                  0.37.0           py39h295c915_1  
>     locket                    0.2.1            py39h06a4308_1  
>     lxml                      4.6.3            py39h9120a33_0  
>     lz4-c                     1.9.3                h295c915_1  
>     lzo                       2.10                 h7b6447c_2  
>     markupsafe                1.1.1            py39h27cfd23_0  
>     matplotlib                3.4.3            py39h06a4308_0  
>     matplotlib-base           3.4.3            py39hbbc1b5f_0  
>     matplotlib-inline         0.1.2              pyhd3eb1b0_2  
>     mccabe                    0.6.1            py39h06a4308_1  
>     mdanalysis                1.0.0            py39he80948d_2    <unknown>
>     mdtraj                    1.9.6            py39h138c130_1    <unknown>
>     mistune                   0.8.4           py39h27cfd23_1000  
>     mkl                       2021.4.0           h06a4308_640  
>     mkl-include               2021.4.0           h06a4308_640    <unknown>
>     mkl-service               2.4.0            py39h7f8727e_0  
>     mkl_fft                   1.3.1            py39hd3c417c_0  
>     mkl_random                1.2.2            py39h51133e4_0  
>     mmtf-python               1.1.2                      py_0    <unknown>
>     mock                      4.0.3              pyhd3eb1b0_0  
>     more-itertools            8.10.0             pyhd3eb1b0_0  
>     mpc                       1.1.0                h10f8cd9_1  
>     mpfr                      4.0.2                hb69a4c5_1  
>     mpmath                    1.2.1            py39h06a4308_0  
>     msgpack-python            1.0.2            py39hff7bd54_1  
>     msmtools                  1.2.6            py39hce5d2b2_0    <unknown>
>     multipledispatch          0.6.0            py39h06a4308_0  
>     multiprocess              0.70.12.2        py39h3811e60_0    <unknown>
>     munkres                   1.1.4                      py_0  
>     mypy_extensions           0.4.3            py39h06a4308_0  
>     navigator-updater         0.2.1            py39h06a4308_0  
>     nbclassic                 0.2.6              pyhd3eb1b0_0  
>     nbclient                  0.5.3              pyhd3eb1b0_0  
>     nbconvert                 6.1.0            py39h06a4308_0  
>     nbdime                    3.1.1              pyhd8ed1ab_0    <unknown>
>     nbformat                  5.1.3              pyhd3eb1b0_0  
>     ncurses                   6.3                  heee7806_1  
>     nest-asyncio              1.5.1              pyhd3eb1b0_0  
>     netcdf4                   1.5.7            py39he70f4c8_0    <unknown>
>     networkx                  2.6.3              pyhd3eb1b0_0  
>     nltk                      3.6.5              pyhd3eb1b0_0  
>     nose                      1.3.7           pyhd3eb1b0_1006  
>     notebook                  6.4.5            py39h06a4308_0  
>     numba                     0.54.1           py39h51133e4_0  
>     numexpr                   2.7.3            py39h22e1b3c_1  
>     numpy                     1.20.3           py39hf144106_0  
>     numpy-base                1.20.3           py39h74d4b33_0  
>     numpydoc                  1.1.0              pyhd3eb1b0_1  
>     olefile                   0.46               pyhd3eb1b0_0  
>     openjpeg                  2.4.0                h3ad879b_0  
>     openpyxl                  3.0.9              pyhd3eb1b0_0  
>     openssl                   1.1.1l               h7f8727e_0  
>     packaging                 21.0               pyhd3eb1b0_0  
>     palettable                3.3.0                      py_0    <unknown>
>     pandas                    1.3.4            py39h8c16a72_0  
>     pandocfilters             1.4.3            py39h06a4308_1  
>     pango                     1.45.3               hd140c19_0  
>     parso                     0.8.2              pyhd3eb1b0_0  
>     partd                     1.2.0              pyhd3eb1b0_0  
>     patchelf                  0.13                 h295c915_0  
>     path                      16.0.0           py39h06a4308_0  
>     path.py                   12.5.0               hd3eb1b0_0  
>     pathlib2                  2.3.6            py39h06a4308_2  
>     pathos                    0.2.8              pyhd8ed1ab_0    <unknown>
>     pathspec                  0.7.0                      py_0  
>     patsy                     0.5.2            py39h06a4308_0  
>     pcre                      8.45                 h295c915_0  
>     pep8                      1.7.1            py39h06a4308_0  
>     pexpect                   4.8.0              pyhd3eb1b0_3  
>     pickleshare               0.7.5           pyhd3eb1b0_1003  
>     pillow                    8.4.0            py39h5aabda8_0  
>     pip                       21.2.4           py39h06a4308_0  
>     pixman                    0.40.0               h7f8727e_1  
>     pkginfo                   1.7.1            py39h06a4308_0  
>     pluggy                    0.13.1           py39h06a4308_0  
>     ply                       3.11             py39h06a4308_0  
>     pox                       0.3.0              pyhd8ed1ab_0    <unknown>
>     poyo                      0.5.0              pyhd3eb1b0_0  
>     ppft                      1.6.6.4            pyhd8ed1ab_0    <unknown>
>     proj                      7.1.1                h966b41f_3    <unknown>
>     prometheus_client         0.11.0             pyhd3eb1b0_0  
>     prompt-toolkit            3.0.20             pyhd3eb1b0_0  
>     prompt_toolkit            3.0.20               hd3eb1b0_0  
>     psutil                    5.8.0            py39h27cfd23_1  
>     ptyprocess                0.7.0              pyhd3eb1b0_2  
>     py                        1.10.0             pyhd3eb1b0_0  
>     py-lief                   0.10.1           py39h2531618_1  
>     pybind11                  2.6.1            py39h081fc7a_0    <unknown>
>     pybind11-global           2.6.1                    pypi_0    pypi
>     pycodestyle               2.7.0              pyhd3eb1b0_0  
>     pycosat                   0.6.3            py39h27cfd23_0  
>     pycparser                 2.20                       py_2  
>     pycurl                    7.44.1           py39h8f2d780_1  
>     pydocstyle                6.1.1              pyhd3eb1b0_0  
>     pyemma                    2.5.9            py39hde0f152_0    <unknown>
>     pyerfa                    2.0.0            py39h27cfd23_0  
>     pyfftw                    0.12.0           py39h51d1ae8_2    <unknown>
>     pyflakes                  2.3.1              pyhd3eb1b0_0  
>     pygments                  2.10.0             pyhd3eb1b0_0  
>     pyhdf                     0.10.2           py39h96f67c4_2    <unknown>
>     pyjwt                     2.1.0            py39h06a4308_0  
>     pylint                    2.9.6            py39h06a4308_1  
>     pyls-spyder               0.4.0              pyhd3eb1b0_0  
>     pyodbc                    4.0.31           py39h295c915_0  
>     pyopenssl                 21.0.0             pyhd3eb1b0_1  
>     pyparsing                 3.0.4              pyhd3eb1b0_0  
>     pyproj                    2.6.1.post1      py39h7ce32b3_3    <unknown>
>     pyqt                      5.9.2            py39h2531618_6  
>     pyrsistent                0.18.0           py39heee7806_0  
>     pyshp                     2.1.3              pyh44b312d_0    <unknown>
>     pysocks                   1.7.1            py39h06a4308_0  
>     pytables                  3.6.1            py39h77479fe_1  
>     pytest                    6.2.4            py39h06a4308_2  
>     python                    3.9.7                h12debd9_1  
>     python-dateutil           2.8.2              pyhd3eb1b0_0  
>     python-libarchive-c       2.9                pyhd3eb1b0_1  
>     python-lsp-black          1.0.0              pyhd3eb1b0_0  
>     python-lsp-jsonrpc        1.0.0              pyhd3eb1b0_0  
>     python-lsp-server         1.2.4              pyhd3eb1b0_0  
>     python-slugify            5.0.2              pyhd3eb1b0_0  
>     python_abi                3.9                      2_cp39    <unknown>
>     pytz                      2021.3             pyhd3eb1b0_0  
>     pywavelets                1.1.1            py39h6323ea4_4  
>     pyxdg                     0.27               pyhd3eb1b0_0  
>     pyyaml                    6.0              py39h7f8727e_1  
>     pyzmq                     22.2.1           py39h295c915_1  
>     qdarkstyle                3.0.2              pyhd3eb1b0_0  
>     qstylizer                 0.1.10             pyhd3eb1b0_0  
>     qt                        5.9.7                h5867ecd_1  
>     qtawesome                 1.0.2              pyhd3eb1b0_0  
>     qtconsole                 5.1.1              pyhd3eb1b0_0  
>     qtpy                      1.10.0             pyhd3eb1b0_0  
>     readline                  8.1                  h27cfd23_0  
>     recommonmark              0.7.1              pyhd8ed1ab_0    <unknown>
>     regex                     2021.8.3         py39h7f8727e_0  
>     requests                  2.26.0             pyhd3eb1b0_0  
>     ripgrep                   12.1.1                        0  
>     rope                      0.19.0             pyhd3eb1b0_0  
>     rtree                     0.9.7            py39h06a4308_1  
>     ruamel_yaml               0.15.100         py39h27cfd23_0  
>     scikit-image              0.18.3           py39h51133e4_0  
>     scikit-learn              0.24.2           py39ha9443f7_0  
>     scipy                     1.7.1            py39h292c36d_2  
>     seaborn                   0.11.2             pyhd3eb1b0_0  
>     secretstorage             3.3.1            py39h06a4308_0  
>     send2trash                1.8.0              pyhd3eb1b0_1  
>     setuptools                58.0.4           py39h06a4308_0  
>     simplegeneric             0.8.1            py39h06a4308_2  
>     singledispatch            3.7.0           pyhd3eb1b0_1001  
>     sip                       4.19.13          py39h2531618_0  
>     six                       1.16.0             pyhd3eb1b0_0  
>     smmap                     3.0.5              pyh44b312d_0    <unknown>
>     snappy                    1.1.8                he6710b0_0  
>     sniffio                   1.2.0            py39h06a4308_1  
>     snowballstemmer           2.1.0              pyhd3eb1b0_0  
>     sortedcollections         2.1.0              pyhd3eb1b0_0  
>     sortedcontainers          2.4.0              pyhd3eb1b0_0  
>     soupsieve                 2.2.1              pyhd3eb1b0_0  
>     sphinx                    4.2.0              pyhd3eb1b0_1  
>     sphinx_rtd_theme          1.0.0              pyhd8ed1ab_0    <unknown>
>     sphinxcontrib             1.0              py39h06a4308_1  
>     sphinxcontrib-applehelp   1.0.2              pyhd3eb1b0_0  
>     sphinxcontrib-devhelp     1.0.2              pyhd3eb1b0_0  
>     sphinxcontrib-htmlhelp    2.0.0              pyhd3eb1b0_0  
>     sphinxcontrib-jsmath      1.0.1              pyhd3eb1b0_0  
>     sphinxcontrib-qthelp      1.0.3              pyhd3eb1b0_0  
>     sphinxcontrib-serializinghtml 1.1.5              pyhd3eb1b0_0  
>     sphinxcontrib-websupport  1.2.4                      py_0  
>     spyder                    5.1.5            py39h06a4308_1  
>     spyder-kernels            2.1.3            py39h06a4308_0  
>     sqlalchemy                1.4.22           py39h7f8727e_0  
>     sqlite                    3.36.0               hc218d9a_0  
>     statsmodels               0.12.2           py39h27cfd23_0  
>     sympy                     1.9              py39h06a4308_0  
>     tbb                       2021.4.0             hd09550d_0  
>     tbb4py                    2021.4.0         py39hd09550d_0  
>     tblib                     1.7.0              pyhd3eb1b0_0  
>     terminado                 0.9.4            py39h06a4308_0  
>     testpath                  0.5.0              pyhd3eb1b0_0  
>     text-unidecode            1.3                pyhd3eb1b0_0  
>     textdistance              4.2.1              pyhd3eb1b0_0  
>     threadpoolctl             2.2.0              pyh0d69192_0  
>     three-merge               0.1.1              pyhd3eb1b0_0  
>     tifffile                  2021.7.2           pyhd3eb1b0_2  
>     tinycss                   0.4             pyhd3eb1b0_1002  
>     tk                        8.6.11               h1ccaba5_0  
>     toml                      0.10.2             pyhd3eb1b0_0  
>     toolz                     0.11.1             pyhd3eb1b0_0  
>     tornado                   6.1              py39h27cfd23_0  
>     tqdm                      4.62.3             pyhd3eb1b0_1  
>     traitlets                 5.1.0              pyhd3eb1b0_0  
>     typed-ast                 1.4.3            py39h7f8727e_1  
>     typing_extensions         3.10.0.2           pyh06a4308_0  
>     tzdata                    2021e                hda174b7_0  
>     ujson                     4.0.2            py39h2531618_0  
>     unicodecsv                0.14.1           py39h06a4308_0  
>     unidecode                 1.2.0              pyhd3eb1b0_0  
>     unixodbc                  2.3.9                h7b6447c_0  
>     urllib3                   1.26.7             pyhd3eb1b0_0  
>     watchdog                  2.1.3            py39h06a4308_0  
>     wcwidth                   0.2.5              pyhd3eb1b0_0  
>     webencodings              0.5.1            py39h06a4308_1  
>     werkzeug                  2.0.2              pyhd3eb1b0_0  
>     wheel                     0.37.0             pyhd3eb1b0_1  
>     whichcraft                0.6.1              pyhd3eb1b0_0  
>     widgetsnbextension        3.5.1            py39h06a4308_0  
>     wrapt                     1.12.1           py39he8ac12f_1  
>     wurlitzer                 2.1.1            py39h06a4308_0  
>     xlrd                      2.0.1              pyhd3eb1b0_0  
>     xlsxwriter                3.0.1              pyhd3eb1b0_0  
>     xlwt                      1.3.0            py39h06a4308_0  
>     xmltodict                 0.12.0             pyhd3eb1b0_0  
>     xz                        5.2.5                h7b6447c_0  
>     yaml                      0.2.5                h7b6447c_0  
>     yapf                      0.31.0             pyhd3eb1b0_0  
>     yt                        3.6.1            py39h6323ea4_0    <unknown>
>     zeromq                    4.3.4                h2531618_0  
>     zfp                       0.5.5                h2531618_6  
>     zict                      2.0.0              pyhd3eb1b0_0  
>     zipp                      3.6.0              pyhd3eb1b0_0  
>     zlib                      1.2.11               h7b6447c_3  
>     zope                      1.0              py39h06a4308_1  
>     zope.event                4.5.0            py39h06a4308_0  
>     zope.interface            5.4.0            py39h7f8727e_0  
>     zstd                      1.4.9                haebb681_0  
> 
>     No errors reported.
> 
> 
>     __Warning log__
>     Warning (cuda): CUDA device intialisation problem. Message:Error at driver init: Call to cuInit results in CUDA_ERROR_NO_DEVICE (100)
>     Exception class: <class 'numba.cuda.cudadrv.error.CudaSupportError'>
>     --------------------------------------------------------------------------------

</details>

I’ll note that whether one gets the warning from Open MPI or not probably depends on how Open MPI is configured. On another machine, I’m not getting the warning even with `objmode()`.

Nevertheless, using `objmode()` does trigger a call to `fork()` even when MPI is not involved at all, and that is what Open MPI seems to be complaining about in my case. Using `strace` on the following modified example, which doesn’t use MPI,

<details>
  <summary>(Trivial) code sample without MPI</summary>

>     import numba
>     
>     @numba.njit
>     def f():
>         with numba.objmode():
>             print(123456)
>     
>     f()

</details>

yields the following:

>     $ strace -e execve,clone -f python3 test-nompi-objmode.py
>     execve("/path/to/packages/x86_64/anaconda/3/2021.11/bin/python3", ["python3", "test-nompi-objmode.py"], 0x7fff5cb10780 /* 113 vars */) = 0
>     clone(child_stack=NULL, flags=CLONE_CHILD_CLEARTID|CLONE_CHILD_SETTID|SIGCHLD, child_tidptr=0x15252d6e4390) = 35787
>     strace: Process 35787 attached
>     [pid 35787] execve("/bin/ip", ["/bin/ip", "link"], 0x55ad7e1e63b0 /* 114 vars */) = 0
>     [pid 35787] +++ exited with 0 +++
>     --- SIGCHLD {si_signo=SIGCHLD, si_code=CLD_EXITED, si_pid=35787, si_uid=28692, si_status=0, si_utime=0, si_stime=0} ---
>     123456
>     +++ exited with 0 +++

whereas removing the line `with numba.objmode()` results in:

>     $ strace -e execve,clone -f python3 test-nompi-noobjmode.py
>     execve("/path/to/packages/x86_64/anaconda/3/2021.11/bin/python3", ["python3", "test-nompi-noobjmode.py"], 0x7ffd42cb37f0 /* 113 vars */) = 0
>     123456
>     +++ exited with 0 +++

Some final notes:
- On the other machine that doesn’t give me the Open MPI warnings (Ubuntu laptop), I’m getting tons of spawned processes (calls to `clone()`) in both cases, i. e. with and without `objmode()`.
- I’m not sure what it’s doing with `execve("/bin/ip", ["/bin/ip", "link"], …)` in there – I’m not getting that on the other machine.
@Socob yes, I think this is because some form of `fork` is called in object mode via `uuid`. However, the only vague reference I have found so far is this:

https://github.com/numba/numba/blob/1d7f47b7d14baf8a7fb8f7f068c23c1ad4196880/numba/tests/test_parallel_backend.py#L940-L944

But I have yet to find the code path in CPython where that `uuid1` call does indeed invoke `fork`.
> But I have yet to find the code path in CPython where that `uuid1` call does indeed invoke `fork`.

@esc assuming it's the same thing, it comes from here: https://github.com/numba/numba/issues/6963#issuecomment-825638042. Python 3.9 deprecated it/changed the call path https://github.com/python/cpython/blob/3.9/Lib/uuid.py#L583-L584, so it's quite possible that you'd need 3.8 to reproduce.


> > But I have yet to find the code path in CPython where that `uuid1` call does indeed invoke `fork`.
> 
> @esc assuming it's the same thing, it comes from here: [#6963 (comment)](https://github.com/numba/numba/issues/6963#issuecomment-825638042). Python 3.9 deprecated it/changed the call path https://github.com/python/cpython/blob/3.9/Lib/uuid.py#L583-L584, so it's quite possible that you'd need 3.8 to reproduce.

OK, does this mean, we can wait for 3.8 to be deprecated and this will become a non-issue? @Socob are you able to use 3.9 and onwards on your hardware?
FYI: Python 3.8 will not be deprecated by NEP 29 until April 2023.
@stuartarchibald @esc: I’m a bit confused – I *am* using Python 3.9 (as seen in `numba -s`). In fact, I’m *only* hitting this issue on 3.8 and 3.9 (that’s why I didn’t notice it before: because I was still using 3.7, which doesn’t seem to trigger this). For comparison, here is what I get using `strace` on different Python versions using a slightly modified example (adding the Python version to the output and some `time.sleep()` calls to show when things are happening):

<details>
  <summary>Modified example script</summary>


>     print('Script start')
>     import time
>     import sys
>     import numba
>     
>     @numba.njit
>     def f():
>         with numba.objmode():
>             print(123456)
>     
>     print('Sleeping for 5 seconds')
>     time.sleep(5)
>     print('Python', sys.version)
>     print('Calling f()')
>     f()
>     print('Sleeping for 5 seconds')
>     time.sleep(5)

</details>


#### Python 3.9:

>     $ strace -e clone,execve -f python3 test-nompi-objmode.py
>     execve("/path/to/packages/x86_64/anaconda/3/2021.11/bin/python3", ["python3", "test-nompi-objmode.py"], 0x7ffca7439820 /* 100 vars */) = 0
>     Script start
>     Sleeping for 5 seconds
>     Python 3.9.7 (default, Sep 16 2021, 13:09:58) 
>     [GCC 7.5.0]
>     Calling f()
>     clone(child_stack=NULL, flags=CLONE_CHILD_CLEARTID|CLONE_CHILD_SETTID|SIGCHLD, child_tidptr=0x153a11c65390) = 25525
>     strace: Process 25525 attached
>     [pid 25525] execve("/bin/ip", ["/bin/ip", "link"], 0x55f99eba5cd0 /* 101 vars */) = 0
>     [pid 25525] +++ exited with 0 +++
>     --- SIGCHLD {si_signo=SIGCHLD, si_code=CLD_EXITED, si_pid=25525, si_uid=28692, si_status=0, si_utime=0, si_stime=0} ---
>     123456
>     Sleeping for 5 seconds
>     +++ exited with 0 +++

#### Python 3.7:

>     $ strace -e clone,execve -f python3 test-nompi-objmode.py
>     execve("/path/to/packages/x86_64/anaconda/3/2020.02/bin/python3", ["python3", "test-nompi-objmode.py"], 0x7ffccc0888d0 /* 99 vars */) = 0
>     Script start
>     clone(child_stack=NULL, flags=CLONE_CHILD_CLEARTID|CLONE_CHILD_SETTID|SIGCHLD, child_tidptr=0x14b88e38e990) = 25789
>     strace: Process 25789 attached
>     [pid 25789] execve("/bin/sh", ["/bin/sh", "-c", "uname -p 2> /dev/null"], 0x7ffc45d8fe70 /* 99 vars */) = 0
>     [pid 25789] clone(child_stack=NULL, flags=CLONE_CHILD_CLEARTID|CLONE_CHILD_SETTID|SIGCHLD, child_tidptr=0x14f785eb6e50) = 25790
>     strace: Process 25790 attached
>     [pid 25790] execve("/usr/bin/uname", ["uname", "-p"], 0x558042916950 /* 99 vars */) = 0
>     [pid 25790] +++ exited with 0 +++
>     [pid 25789] --- SIGCHLD {si_signo=SIGCHLD, si_code=CLD_EXITED, si_pid=25790, si_uid=28692, si_status=0, si_utime=0, si_stime=0} ---
>     [pid 25789] +++ exited with 0 +++
>     --- SIGCHLD {si_signo=SIGCHLD, si_code=CLD_EXITED, si_pid=25789, si_uid=28692, si_status=0, si_utime=0, si_stime=0} ---
>     Sleeping for 5 seconds
>     Python 3.7.6 (default, Jan  8 2020, 19:59:22) 
>     [GCC 7.3.0]
>     Calling f()
>     123456
>     Sleeping for 5 seconds
>     +++ exited with 0 +++

There’s a `clone()` in there for both versions, but in 3.7 Open MPI doesn’t complain about that – presumably because in 3.7, the `fork()` happens when `numba` is imported (which just happened to be before MPI was initialized by importing `mpi4py` in my case), whereas in 3.9, the process is forked at the time that `f()` is called. If I import `numba` after `mpi4py`, I always get a warning when importing `numba` in Python 3.7 (but not in 3.9, which doesn’t seem to trigger `fork()` when `numba` is imported).
In the above, Python 3.9 looks like it's calling `/bin/ip link` from within a `uuid.uuid1` call. The reason `uuid1` is being called is that serialization of an object mode dispatcher requires it.

Back trace that captures all this:
```
  <site-packages>/numba/core/lowering.py(953)_lower_call_ObjModeDispatcher()
-> callee = ObjModeUtils(self.pyapi).load_dispatcher(fnty, argtypes)
  <site-packages>/numba/core/pythonapi.py(1640)load_dispatcher()
-> if serialize.is_serialiable(fnty.dispatcher):
  <site-packages>/numba/core/serialize.py(156)is_serialiable()
-> pickler.dump(obj)
  <site-packages>/numba/cloudpickle/cloudpickle_fast.py(568)dump()
-> return Pickler.dump(self, obj)
  <site-packages>/numba/core/serialize.py(218)__reduce__()
-> return custom_reduce(self._reduce_class(), self._reduce_states())
  <site-packages>/numba/core/dispatcher.py(1113)_reduce_states()
-> uuid=self._uuid, func_ir=self.func_ir, flags=self.flags,
  <site-packages>/numba/core/dispatcher.py(781)_uuid()
-> u = str(uuid.uuid1())
  <pypath>/python3.9/uuid.py(700)uuid1()
-> node = getnode()
  <pypath>/python3.9/uuid.py(656)getnode()
-> _node = getter()
  <pypath>/python3.9/uuid.py(518)_ip_getnode()
-> mac = _find_mac_near_keyword('ip', 'link', [b'link/ether'], lambda i: i+1)
  <pypath>/python3.9/uuid.py(413)_find_mac_near_keyword()
-> stdout = _get_command_stdout(command, args)
  <pypath>/python3.9/uuid.py(373)_get_command_stdout()
-> proc = subprocess.Popen((executable,) + args,
  <pypath>/python3.9/subprocess.py(951)__init__()
-> self._execute_child(args, executable, preexec_fn, close_fds,
> <pypath>/python3.9/subprocess.py(1755)_execute_child()
-> self.pid = _posixsubprocess.fork_exec(...)
```

Note that this `uuid1` call is happening at compile time, not during execution. Running the same script but with a signature supplied to `f` such that compilation happens on import leads to no `execve` call at the perceived point of execution:
```python
print('Script start')
import time
import sys
import numba

@numba.njit('void()')
def f():
    with numba.objmode():
        print(123456)

print('Sleeping for 5 seconds')
time.sleep(5)
print('Python', sys.version)
print('Calling f()')
f()
print('Sleeping for 5 seconds')
time.sleep(5)
```
Could we switch to another uuid method that doesn't require starting a subprocess? (why Python, why??)
@stuartarchibald Right, of course I assumed that the thing causing a process to be spawned was the compilation and not the function call itself (which caused the compilation in this case). While adding a signature as you suggested does move the offending process creation to the point of function definition, this would still require me to import `mpi4py` only *after* defining and creating any affected `numba` functions – not really practical!

I’m wondering why Python 3.7 doesn’t seem to require a subprocess for `uuid1`, though. Perhaps something similar is still available in 3.9 (in the same vein as @seibert’s comment)?
> Could we switch to another uuid method that doesn't require starting a subprocess? (why Python, why??)

The `uuid.uuid1` function makes a one-off call to `getnode`:
```
In [12]: uuid.getnode?
Signature: uuid.getnode()
Docstring:
Get the hardware address as a 48-bit positive integer.

The first time this runs, it may launch a separate program, which could
be quite slow.  If all attempts to obtain the hardware address fail, we
choose a random 48-bit number with its eighth bit set to 1 as recommended
in RFC 4122.
```
which on Python 3.9 will go via `ip link`. On Python 3.7 a more `ctypes` querying a library based approach was taken (which would probably avoid fork+exec): https://github.com/python/cpython/blob/3.7/Lib/uuid.py#L588-L639.

The `uuid1()` function takes a `node` kwarg:
```
In [36]: uuid.uuid1?
Signature: uuid.uuid1(node=None, clock_seq=None)
Docstring:
Generate a UUID from a host ID, sequence number, and the current time.
If 'node' is not given, getnode() is used to obtain the hardware
address.  If 'clock_seq' is given, it is used as the sequence number;
otherwise a random 14-bit sequence number is chosen.
```
which might be something that could be supplied. Alternatively I think it would be ok to use `uuid4`, it's just to act as a cache key to speed up serialisation AFAICT.
> @stuartarchibald Right, of course I assumed that the thing causing a process to be spawned was the compilation and not the function call itself (which caused the compilation in this case). While adding a signature as you suggested does move the offending process creation to the point of function definition, this would still require me to import `mpi4py` only _after_ defining and creating any affected `numba` functions – not really practical!

Indeed, adding function signatures is definitely not the way to fix this, it was more about demonstrating that it's definitely the compilation part that is triggering the fork+exec.

> I’m wondering why Python 3.7 doesn’t seem to require a subprocess for `uuid1`, though. Perhaps something similar is still available in 3.9 (in the same vein as @seibert’s comment)?

See notes above, hopefully that explains it.


Resolving patch:
diff --git a/numba/core/dispatcher.py b/numba/core/dispatcher.py
--- a/numba/core/dispatcher.py
+++ b/numba/core/dispatcher.py
@@ -778,7 +778,7 @@ def _uuid(self):
         """
         u = self.__uuid
         if u is None:
-            u = str(uuid.uuid1())
+            u = str(uuid.uuid4())
             self._set_uuid(u)
         return u
 


Test patch:
diff --git a/numba/tests/support.py b/numba/tests/support.py
--- a/numba/tests/support.py
+++ b/numba/tests/support.py
@@ -9,10 +9,12 @@
 import math
 import platform
 import os
+import signal
 import shutil
 import subprocess
 import sys
 import tempfile
+import threading
 import time
 import io
 import ctypes
@@ -1007,6 +1009,90 @@ def run_in_subprocess(code, flags=None, env=None, timeout=30):
     return out, err
 
 
+def strace(work, syscalls, timeout=10):
+    """Runs strace whilst executing the function work() in the current process,
+    captures the listed syscalls (list of strings). Takes an optional timeout in
+    seconds, default is 10, if this is exceeded the process will be sent a
+    SIGKILL. Returns a list of lines that are output by strace.
+    """
+
+    # Open a tmpfile for strace to write into.
+    with tempfile.NamedTemporaryFile('w+t') as ntf:
+
+        parent_pid = os.getpid()
+        strace_binary = shutil.which('strace')
+        if strace_binary is None:
+            raise ValueError("No valid 'strace' binary could be found")
+        cmd = ['strace', # strace
+            '-q', # quietly (no attach/detach print out)
+            '-p', str(parent_pid), # this PID
+            '-e', ','.join(syscalls), # these syscalls
+            '-o', ntf.name] # put output into this file
+
+        # redirect stdout, stderr is handled by the `-o` flag to strace.
+        popen = subprocess.Popen(cmd, stdout=subprocess.PIPE,)
+        strace_pid = popen.pid
+        thread_timeout = threading.Timer(timeout, popen.kill)
+        thread_timeout.start()
+
+        def check_return(problem=''):
+            ret = popen.returncode
+            if ret != 0:
+                msg = ("strace exited non-zero, process return code was:"
+                       f"{ret}. {problem}")
+                raise RuntimeError(msg)
+        try:
+            # push the communication onto a thread so it doesn't block.
+            # start comms thread
+            thread_comms = threading.Thread(target=popen.communicate)
+            thread_comms.start()
+
+            # do work
+            work()
+            # Flush the output buffer file
+            ntf.flush()
+            # interrupt the strace process to stop it if it's still running
+            if popen.poll() is None:
+                os.kill(strace_pid, signal.SIGINT)
+            else:
+                # it's not running, probably an issue, raise
+                problem="If this is SIGKILL, increase the timeout?"
+                check_return(problem)
+            # Make sure the return code is 0, SIGINT to detach is considered
+            # a successful exit.
+            popen.wait()
+            check_return()
+            # collect the data
+            strace_data = ntf.readlines()
+        finally:
+            # join communication, should be stopped now as process has
+            # exited
+            thread_comms.join()
+            # should be stopped already
+            thread_timeout.cancel()
+
+    return strace_data
+
+
+def _strace_supported():
+    """Checks if strace is supported and working"""
+    def force_clone(): # subprocess triggers a clone
+        subprocess.run([sys.executable, '-c', 'exit()'])
+
+    syscall = 'clone'
+    try:
+        trace = strace(force_clone, [syscall,])
+    except Exception:
+        return False
+    return syscall in ''.join(trace)
+
+
+_HAVE_STRACE = _strace_supported()
+
+
+needs_strace = unittest.skipUnless(_HAVE_STRACE, "needs working strace")
+
+
 class IRPreservingTestPipeline(CompilerBase):
     """ Same as the standard pipeline, but preserves the func_ir into the
     metadata store after legalisation, useful for testing IR changes"""
diff --git a/numba/tests/test_withlifting.py b/numba/tests/test_withlifting.py
--- a/numba/tests/test_withlifting.py
+++ b/numba/tests/test_withlifting.py
@@ -1,4 +1,10 @@
 import copy
+import os
+import signal
+import subprocess
+import sys
+import tempfile
+import threading
 import warnings
 import numpy as np
 
@@ -13,7 +19,8 @@
 from numba import njit, typeof, objmode, types
 from numba.core.extending import overload
 from numba.tests.support import (MemoryLeak, TestCase, captured_stdout,
-                                 skip_unless_scipy)
+                                 skip_unless_scipy, needs_strace, linux_only,
+                                 strace, needs_subprocess)
 from numba.core.utils import PYVERSION
 from numba.experimental import jitclass
 import unittest
@@ -1213,5 +1220,44 @@ def foo():
         self.assertIn(msg, excstr)
 
 
+class TestMisc(TestCase):
+    # Tests for miscellaneous objmode issues. Run serially.
+
+    _numba_parallel_test_ = False
+
+    @linux_only
+    @needs_strace
+    @needs_subprocess
+    def test_no_fork_in_compilation_impl(self):
+        # Checks that there is no fork/clone/execve during compilation, see
+        # issue #7881. This needs running in a subprocess as the offending fork
+        # call that triggered #7881 occurs on the first call to uuid1 as it's
+        # part if the initialisation process for that function (gets hardware
+        # address of machine).
+
+        def force_compile():
+            @njit('void()') # force compilation
+            def f():
+                with numba.objmode():
+                    pass
+
+        # capture these syscalls:
+        syscalls = ['fork', 'clone', 'execve']
+
+        # check that compilation does not trigger fork, clone or execve
+        strace_data = strace(force_compile, syscalls)
+        self.assertFalse(strace_data)
+
+    @linux_only
+    @needs_strace
+    def test_no_fork_in_compilation(self):
+        # Runs the test_no_fork_in_compilation_impl test in a subprocess
+        themod = f'numba.tests.test_withlifting'
+        testname = 'test_no_fork_in_compilation_impl'
+        self.subprocess_test_runner(test_module=themod,
+                                    test_class='TestMisc',
+                                    test_name=testname,)
+
+
 if __name__ == '__main__':
     unittest.main()