Summary:
- C-API takes opaque context type as first arg
- context is as specific as possible
- separate Py_Main() from runtime initialization
- separate global init from interpreter init
- explicit enabling/disabling runtime components
_PyRuntimeState_GetThreadState() | |
_PyRuntime.gilstate.tstate_current <---- | |
_PyRuntimeGILState_GetThreadState() | |
_PyRuntime.gilstate.tstate_current <---- | |
_PyRuntimeGILState_SetThreadState(tstate) | |
_PyRuntime.gilstate.tstate_current = tstate <---- |
Comparing:
left: https://github.com/Kronuz/cpython/commit/553d3c10172254b190078c50eb9f8e60522c8f41 right: https://github.com/Kronuz/cpython/commit/44b7e9b87676e0bccde43103a4c954c8d79de017 (aka kronuz/lazy_imports)
No change in performance
$ bench-jobs compare req-compile-bench-1666307353-esnow-linux req-compile-bench-1666307369-esnow-linux
[snip]
import contextlib | |
import os | |
import sys | |
try: | |
from io import StringIO as StdioStream | |
except ImportError: | |
from StringIO import StringIO # 2.7 | |
class StdioStream(StringIO): |
""" | |
This is a script for working around the lack of ensurepip in | |
Ubuntu's system Python installs. | |
See: https://bugs.launchpad.net/ubuntu/+source/python3.4/+bug/1290847 | |
An alternative is the following: | |
$ python3 -m venv --without-pip my-venv | |
$ curl https://bootstrap.pypa.io/get-pip.py | |
$ my-venv/bin/python3 get-pip.py |
import importlib.machinery | |
import importlib.util | |
import sys | |
def load_lazydb(infile): |
import subprocess | |
args = [sys.executable, '-v', '-c', 'pass'] | |
if not withsite: | |
args.insert(1, '-S') | |
out = subprocess.check_output(args, stderr=subprocess.STDOUT).decode() | |
imported = [line.split("'")[1] | |
for line in out.splitlines() | |
if line.startswith("import '")] | |
for name in imported: | |
try: |