Repository: yt-project/yt

Issue:
parallel cython build ends up in infinite recursion on macOS in yt-4.0
<!--To help us understand and resolve your issue, please fill out the form to
the best of your ability.-->
<!--You can feel free to delete the sections that do not apply.-->

### Bug report

**Bug summary**

We started using all available cores to build yt-4.0 from source in PR https://github.com/yt-project/yt/pull/2438. I recently tried to build on macOS and ended up in an infinite recursion. The huge traceback is here:

http://paste.yt-project.org/show/225/

**Code for reproduction**

Simply trying to install yt-4.0 from source in `python setup.py develop` or `pip install -e .` triggers this. If I comment out lines 22 and 23 here (disabling the parallel build) the problem goes away:

https://github.com/yt-project/yt/blob/d99f816300fc5bf9888eccea02adda76289d51c5/setup.py#L21-L24

I have no idea if we have to treat macOS like Windows or if there's some way we can make it work. 

**Version Information**
<!--Please specify your platform and versions of the relevant libraries you are
using:-->
  * Operating System: macOS 10.15.3
  * Python Version: 3.8.2
  * yt version: 4.0



Discussion:
I can't reproduce on OSX I have access to. Which compiler are you using?
clang:
```
gcc --version
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/4.2.1
Apple clang version 11.0.3 (clang-1103.0.32.59)
Target: x86_64-apple-darwin19.3.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
```
This seems to be a Python 3.8 thing also, as I tried this on my 3.7 installation and it worked fine. 
Could you try adding `import multiprocessing` at the top of the `setup.py` and see if that changes anything?
Sadly no. What seems to happen is that multiple copies of everything in `setup.py` runs. 

Resolving patch:
diff --git a/setup.py b/setup.py
--- a/setup.py
+++ b/setup.py
@@ -387,63 +387,65 @@ def run(self):
         )
         _sdist.run(self)
 
-setup(
-    name="yt",
-    version=VERSION,
-    description="An analysis and visualization toolkit for volumetric data",
-    long_description = long_description,
-    long_description_content_type='text/markdown',
-    classifiers=["Development Status :: 5 - Production/Stable",
-                 "Environment :: Console",
-                 "Intended Audience :: Science/Research",
-                 "License :: OSI Approved :: BSD License",
-                 "Operating System :: MacOS :: MacOS X",
-                 "Operating System :: POSIX :: AIX",
-                 "Operating System :: POSIX :: Linux",
-                 "Programming Language :: C",
-                 "Programming Language :: Python :: 3",
-                 "Programming Language :: Python :: 3.5",
-                 "Programming Language :: Python :: 3.6",
-                 "Programming Language :: Python :: 3.7",
-                 "Topic :: Scientific/Engineering :: Astronomy",
-                 "Topic :: Scientific/Engineering :: Physics",
-                 "Topic :: Scientific/Engineering :: Visualization"],
-    keywords='astronomy astrophysics visualization ' +
-    'amr adaptivemeshrefinement',
-    entry_points={'console_scripts': [
-        'yt = yt.utilities.command_line:run_main',
-    ],
-        'nose.plugins.0.10': [
-            'answer-testing = yt.utilities.answer_testing.framework:AnswerTesting'
-    ]
-    },
-    packages=find_packages(),
-    include_package_data = True,
-    install_requires=[
-        'matplotlib>=1.5.3',
-        'setuptools>=19.6',
-        'sympy>=1.2',
-        'numpy>=1.10.4',
-        'IPython>=1.0',
-        'unyt>=2.2.2',
-    ],
-    extras_require = {
-        'hub':  ["girder_client"],
-        'mapserver': ["bottle"]
-    },
-    cmdclass={'sdist': sdist, 'build_ext': build_ext},
-    author="The yt project",
-    author_email="yt-dev@python.org",
-    url="https://github.com/yt-project/yt",
-    project_urls={
-        'Homepage': 'https://yt-project.org/',
-        'Documentation': 'https://yt-project.org/doc/',
-        'Source': 'https://github.com/yt-project/yt/',
-        'Tracker': 'https://github.com/yt-project/yt/issues'
-    },
-    license="BSD 3-Clause",
-    zip_safe=False,
-    scripts=["scripts/iyt"],
-    ext_modules=cython_extensions + extensions,
-    python_requires='>=2.7,!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,!=3.4.*'
-)
+
+if __name__ == "__main__":
+    setup(
+        name="yt",
+        version=VERSION,
+        description="An analysis and visualization toolkit for volumetric data",
+        long_description = long_description,
+        long_description_content_type='text/markdown',
+        classifiers=["Development Status :: 5 - Production/Stable",
+                     "Environment :: Console",
+                     "Intended Audience :: Science/Research",
+                     "License :: OSI Approved :: BSD License",
+                     "Operating System :: MacOS :: MacOS X",
+                     "Operating System :: POSIX :: AIX",
+                     "Operating System :: POSIX :: Linux",
+                     "Programming Language :: C",
+                     "Programming Language :: Python :: 3",
+                     "Programming Language :: Python :: 3.5",
+                     "Programming Language :: Python :: 3.6",
+                     "Programming Language :: Python :: 3.7",
+                     "Topic :: Scientific/Engineering :: Astronomy",
+                     "Topic :: Scientific/Engineering :: Physics",
+                     "Topic :: Scientific/Engineering :: Visualization"],
+        keywords='astronomy astrophysics visualization ' +
+        'amr adaptivemeshrefinement',
+        entry_points={'console_scripts': [
+            'yt = yt.utilities.command_line:run_main',
+        ],
+            'nose.plugins.0.10': [
+                'answer-testing = yt.utilities.answer_testing.framework:AnswerTesting'
+        ]
+        },
+        packages=find_packages(),
+        include_package_data = True,
+        install_requires=[
+            'matplotlib>=1.5.3',
+            'setuptools>=19.6',
+            'sympy>=1.2',
+            'numpy>=1.10.4',
+            'IPython>=1.0',
+            'unyt>=2.2.2',
+        ],
+        extras_require = {
+            'hub':  ["girder_client"],
+            'mapserver': ["bottle"]
+        },
+        cmdclass={'sdist': sdist, 'build_ext': build_ext},
+        author="The yt project",
+        author_email="yt-dev@python.org",
+        url="https://github.com/yt-project/yt",
+        project_urls={
+            'Homepage': 'https://yt-project.org/',
+            'Documentation': 'https://yt-project.org/doc/',
+            'Source': 'https://github.com/yt-project/yt/',
+            'Tracker': 'https://github.com/yt-project/yt/issues'
+        },
+        license="BSD 3-Clause",
+        zip_safe=False,
+        scripts=["scripts/iyt"],
+        ext_modules=cython_extensions + extensions,
+        python_requires='>=2.7,!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,!=3.4.*'
+    )


Test patch: