Commit ff0c1041 authored by Kirill Smelkov's avatar Kirill Smelkov

gpython: Fix `gpython -X gpython.runtime=threads` to spawn subinterpreters...

gpython: Fix `gpython -X gpython.runtime=threads` to spawn subinterpreters with threads runtime by default

Previously it was not the case and gpython with default being gevent
runtime was spawned even if parent gpython was instructed to use threads runtime:

    (z-dev) kirr@deca:~/src/tools/go/pygolang$ gpython -X gpython.runtime=threads
    Python 2.7.18 (default, Apr 28 2021, 17:39:59)
    [GCC 10.2.1 20210110] [GPython 0.1] [threads] on linux2
    Type "help", "copyright", "credits" or "license" for more information.
    (InteractiveConsole)
    >>> import sys
    >>> sys.version
    '2.7.18 (default, Apr 28 2021, 17:39:59) \n[GCC 10.2.1 20210110] [GPython 0.1] [threads]'   <-- NOTE threads
    >>> import subprocess
    subprocess.call(sys.executable)
    Python 2.7.18 (default, Apr 28 2021, 17:39:59)
    [GCC 10.2.1 20210110] [GPython 0.1] [gevent 21.1.2] on linux2                               <-- NOTE gevent
    Type "help", "copyright", "credits" or "license" for more information.
    (InteractiveConsole)
    >>>

/proposed-for-review-on !25
parent 4da04314
......@@ -409,6 +409,11 @@ def main():
argv = [sys.argv[0]] + argv_ + igetopt.argv
# propagate those settings as defaults to subinterpreters, so that e.g.
# sys.executable spawned from under `gpython -X gpython.runtime=threads`
# also uses "threads" runtime by default.
os.environ['GPYTHON_RUNTIME'] = gpy_runtime
# init initializes according to selected runtime
# it is called after options are parsed and sys.path is setup correspondingly.
# this way golang and gevent are imported from exactly the same place as
......
......@@ -365,6 +365,9 @@ def test_Xruntime(runtime):
# _xopt_assert_in_subprocess runs tfunc in subprocess interpreter spawned with
# `-X xopt=xval` and checks that there is no error.
#
# It is also verified that tfunc runs ok in sub-subprocess interpreter spawned
# _without_ `-X ...`, i.e. once given -X setting is inherited by spawned interpreters.
def _xopt_assert_in_subprocess(xopt, xval, tfunc):
XOPT = xopt.upper().replace('.','_') # gpython.runtime -> GPYTHON_RUNTIME
env = os.environ.copy()
......@@ -373,8 +376,10 @@ def _xopt_assert_in_subprocess(xopt, xval, tfunc):
argv = []
if xval != '':
argv += ['-X', xopt+'='+xval]
prog = 'from gpython import gpython_test as t; '
prog = import_t = 'from gpython import gpython_test as t; '
prog += 't.%s(); ' % tfunc.__name__
prog += import_t # + same in subprocess
prog += "t.pyrun(['-c', '%s t.%s(); ']); " % (import_t, tfunc.__name__)
prog += 'print("ok")'
argv += ['-c', prog]
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment