Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't preimport threading early #1897

Merged
merged 5 commits into from Jul 15, 2020
Merged

Commits on Jul 14, 2020

  1. Don't preimport threading early

    Gevent-based applications need to be able to import threading, socket,
    ssl, etc... modules early to be able to monkey-patch them to use
    lightweight greenlets instead of OS threads. This patching has to be
    done as early as possible in the lifetime of the process
    
    http://www.gevent.org/intro.html#monkey-patching
    
    However starting from caae48b (use import hooks to patch
    distutils/setuptools (pypa#1688)) threading became always preimported which,
    for example, rendered gpython[1] unusable:
    
    	(py38.virtualenv) kirr@deco:~/tmp/trashme$ gpython
    	Traceback (most recent call last):
    	  File "/home/kirr/tmp/trashme/py38.virtualenv/bin/gpython", line 8, in <module>
    	    sys.exit(main())
    	  File "/home/kirr/tmp/trashme/py38.virtualenv/lib/python3.8/site-packages/gpython/__init__.py", line 151, in main
    	    raise RuntimeError('gpython: internal error: the following modules are pre-imported, but must be not:'
    	RuntimeError: gpython: internal error: the following modules are pre-imported, but must be not:
    
    	        ['threading']
    
    	sys.modules:
    
    	        ['__future__', '__main__', '_abc', '_bootlocale', '_codecs', '_collections', '_collections_abc', '_frozen_importlib', '_frozen_importlib_external', '_functools', '_heapq', '_imp', '_io', '_locale', '_operator', '_signal', '_sitebuiltins', '_sre', '_stat', '_thread', '_virtualenv', '_warnings', '_weakref', '_weakrefset', 'abc', 'builtins', 'codecs', 'collections', 'contextlib', 'copyreg', 'encodings', 'encodings.aliases', 'encodings.latin_1', 'encodings.utf_8', 'enum', 'functools', 'genericpath', 'gpython', 'heapq', 'importlib', 'importlib._bootstrap', 'importlib._bootstrap_external', 'importlib.abc', 'importlib.machinery', 'importlib.util', 'io', 'itertools', 'keyword', 'marshal', 'operator', 'os', 'os.path', 'posix', 'posixpath', 're', 'reprlib', 'site', 'sitecustomize', 'sre_compile', 'sre_constants', 'sre_parse', 'stat', 'sys', 'threading', 'time', 'types', 'warnings', 'zipimport', 'zope']
    
    Fix it by importing threading lazily.
    
    Fixes: pypa#1895
    
    [1] https://pypi.org/project/pygolang/#gpython
    navytux committed Jul 14, 2020
    Configuration menu
    Copy the full SHA
    eb0a18a View commit details
    Browse the repository at this point in the history
  2. fixup! Don't preimport threading early

    AttributeError("'PosixPath' object has no attribute 'rfind'",)
    navytux committed Jul 14, 2020
    Configuration menu
    Copy the full SHA
    74e8e4d View commit details
    Browse the repository at this point in the history
  3. fixup! Don't preimport threading early

    Address review feedback:
    
    - wrap comments at 120 characters;
    - use "imported" instead of "preimport" in tests and leverage python
      syntax sugar to raise signal/noise;
    - inline links in changelog
    
    Try to fix test failures:
    
    - try to disable coverage for spawned subrocess.
    
      However in the presence of coverage-enable-subprocess coverge is still
      unconditioanlly imported, and even plain `import coverage` leads to
      `import threading`. Probably need to fix coverage as well.
    navytux committed Jul 14, 2020
    Configuration menu
    Copy the full SHA
    6738c67 View commit details
    Browse the repository at this point in the history
  4. fixup! Don't preimport threading early

    Disable coverage for the test as suggested by @gaborbernat.
    navytux committed Jul 14, 2020
    Configuration menu
    Copy the full SHA
    44ace84 View commit details
    Browse the repository at this point in the history

Commits on Jul 15, 2020

  1. fixup! Don't preimport threading early

    Xfail on pypy3/darwin. See reason link for details.
    navytux committed Jul 15, 2020
    Configuration menu
    Copy the full SHA
    1398a9d View commit details
    Browse the repository at this point in the history