Skip to content

Python sub-interpreter test #55123

Closed
Closed

Description

@pitrou
BPO 10914
Nosy @loewis, @amauryfa, @ncoghlan, @pitrou, @vstinner, @tiran, @benjaminp, @tarekziade, @merwok, @ericsnowcurrently
Files
  • embedtest.patch
  • embedtest-distutils.patch
  • embedtest2.patch
  • fscodec_subinterpreter.patch
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = 'https://github.com/vstinner'
    closed_at = <Date 2011-04-30.12:21:19.771>
    created_at = <Date 2011-01-15.13:38:37.736>
    labels = ['interpreter-core', 'tests']
    title = 'Python sub-interpreter test'
    updated_at = <Date 2012-11-28.06:45:09.320>
    user = 'https://github.com/pitrou'

    bugs.python.org fields:

    activity = <Date 2012-11-28.06:45:09.320>
    actor = 'eric.snow'
    assignee = 'vstinner'
    closed = True
    closed_date = <Date 2011-04-30.12:21:19.771>
    closer = 'vstinner'
    components = ['Interpreter Core', 'Tests']
    creation = <Date 2011-01-15.13:38:37.736>
    creator = 'pitrou'
    dependencies = []
    files = ['20414', '21282', '21765', '21778']
    hgrepos = []
    issue_num = 10914
    keywords = ['patch']
    message_count = 33.0
    messages = ['126328', '126380', '126382', '126384', '126385', '126401', '126403', '131295', '131296', '131302', '131303', '131321', '131360', '132106', '134334', '134335', '134336', '134404', '134405', '134413', '134417', '134421', '134423', '134425', '134510', '134515', '134606', '134855', '134857', '143464', '143498', '143518', '143519']
    nosy_count = 12.0
    nosy_names = ['loewis', 'amaury.forgeotdarc', 'ncoghlan', 'pitrou', 'vstinner', 'christian.heimes', 'benjamin.peterson', 'tarek', 'eric.araujo', 'grahamd', 'python-dev', 'eric.snow']
    pr_nums = []
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = None
    url = 'https://bugs.python.org/issue10914'
    versions = ['Python 3.2', 'Python 3.3']

    Activity

    1. pitrou commented on Jan 15, 2011

      @pitrou
      MemberAuthor

      Here is a prototype test for embedding and sub-interpreters.

    2. added
      interpreter-core(Objects, Python, Grammar, and Parser dirs)
      testsTests in the Lib/test dir
      on Jan 15, 2011
    3. amauryfa commented on Jan 16, 2011

      @amauryfa
      Contributor

      +1 for this kind of tests.
      But I would not have their source in the "official" Modules directory. I expect that there will be several tests of this kind, each one with different modules to import, functions to run, global settings to change.
      IMO the C code should be somewhere in the test directory; later we could use templates to generate source code for similar tests.

      Is it possible to use distutils to compile this test, and remove it from the Makefile?

    4. benjaminp commented on Jan 16, 2011

      @benjaminp
      Contributor

      There's already precedent for test modules in Modules/ what with xxmodule.c and _testcapimodule.c.

    5. pitrou commented on Jan 16, 2011

      @pitrou
      MemberAuthor

      Is it possible to use distutils to compile this test, and remove it
      from the Makefile?

      I'm not aware that distutils is able to compile applications rather than
      extension modules, but that would certainly be better than a rule in the
      Makefile, yes.

    6. amauryfa commented on Jan 16, 2011

      @amauryfa
      Contributor

      In distutils.command.config, config().try_run(body) is probably what we need. Now, I don't know how to use it...

    7. ncoghlan commented on Jan 17, 2011

      @ncoghlan
      Contributor

      I like the idea of adding these tests as well.

      Probably worth bringing up on python-dev - folks like Tarek should definitely be able to help with alternative ways of building a test application for this.

      There is also always the possibility of writing it in Python and using ctypes to get at the necessary C API calls to create subinterpreters.

    8. pitrou commented on Jan 17, 2011

      @pitrou
      MemberAuthor

      There is also always the possibility of writing it in Python and using
      ctypes to get at the necessary C API calls to create subinterpreters.

      Well, I don't think calling Py_Initialize, Py_Finalize and Py_NewInterpreter from pure Python code is a very good idea.

      Tarek, can you help? We'd like to use distutils to compile an executable embedding the interpreter.

    9. python-dev commented on Mar 17, 2011

      python-devmannequin
      Mannequin

      New changeset a791dd7d51f3 by Antoine Pitrou in branch '3.2':
      Issue bpo-10914: fix bogus memory management in Modules/getpath.c, leading to a possible crash when calling Py_SetPath()
      http://hg.python.org/cpython/rev/a791dd7d51f3

    10. pitrou commented on Mar 17, 2011

      @pitrou
      MemberAuthor

      Ouch, sorry, I got my commit message wrong.

    11. merwok commented on Mar 17, 2011

      @merwok
      Member

      distutils sure knows how to build .o or .so files, but I don’t know about standalone executables (because I don’t know how the .o end up making an executable). If you want to try to do it, I would advise you not to use the config command but rather a compiler object directly. distutils.ccompiler.new_compiler() should give you an instance of a subclass of distutils.ccompiler.CCompiler suitable for your system, and then you can use help or the source to find what methods to call.

    12. pitrou commented on Mar 17, 2011

      @pitrou
      MemberAuthor

      distutils sure knows how to build .o or .so files, but I don’t know
      about standalone executables (because I don’t know how the .o end up
      making an executable). If you want to try to do it, I would advise
      you not to use the config command but rather a compiler object
      directly. distutils.ccompiler.new_compiler() should give you an
      instance of a subclass of distutils.ccompiler.CCompiler suitable for
      your system, and then you can use help or the source to find what
      methods to call.

      Well, config._link() seems to do what is needed here. If you think it is
      bad to rely on it, perhaps we should "inline" its code somehow in the
      test module.

    13. merwok commented on Mar 18, 2011

      @merwok
      Member

      Well, config._link() seems to do what is needed here.
      My point is that it’s easier to write a few lines of code directly using a compiler object (copying and simplifying code from try_run or _link) than go through the distutils command machinery. Both are doable, but I think the former is easier.

    14. pitrou commented on Mar 18, 2011

      @pitrou
      MemberAuthor

      Ok, this is what I came up with to build an exe using distutils. At this point, the complication is downright silly and it doesn't even work under Windows, so we may prefer to go down the Makefile route instead.

    15. 10 remaining items

    16. vstinner commented on Apr 25, 2011

      @vstinner
      Member

      The problem is the test on the "python initialization":
      PyUnicode_EncodeFSDefault / PyUnicode_DecodeFSDefaultAndSize
      check the global Py_FileSystemDefaultEncoding variable (use
      C functions if it is NULL).

      The problem is a little bit more complex. interp->codecs_initialized is set to 1 by _PyCodecRegistry_Init(), but the filesystem codec is not loaded yet. We need another variable: interp->fscodec_initialized.

      fscodec_subinterpreter.patch fixes this issue.

      Note: the patch replaces also PyErr_Print() by PyErr_PrintEx(0) to avoid a crash on error, if PyErr_PrintEx(0) is called before the sys module is initialized. For example, if PyModule_GetDict(_PyImport_FindBuiltin("builtins")) is NULL. Anyway, it's useless to set sys attributes on error, because sys is destroyed just after printing the error.

    17. python-dev commented on Apr 26, 2011

      python-devmannequin
      Mannequin

      New changeset c8338cfa3578 by Victor Stinner in branch 'default':
      Issue bpo-10914: Py_NewInterpreter() uses PyErr_PrintEx(0)
      http://hg.python.org/cpython/rev/c8338cfa3578

      New changeset d3af2a2b621b by Victor Stinner in branch 'default':
      Issue bpo-10914: Initialize correctly the filesystem codec when creating a new
      http://hg.python.org/cpython/rev/d3af2a2b621b

    18. vstinner commented on Apr 26, 2011

      @vstinner
      Member

      test_capi pass on x86 debian parallel 3.x: I close this issue again :-)

    19. pitrou commented on Apr 27, 2011

      @pitrou
      MemberAuthor

      Victor, the fix needs to go into 3.2 as well.

    20. reopened this on Apr 27, 2011
    21. python-dev commented on Apr 30, 2011

      python-devmannequin
      Mannequin

      New changeset 5a983773c09a by Victor Stinner in branch '3.2':
      Issue bpo-10914: Py_NewInterpreter() uses PyErr_PrintEx(0)
      http://hg.python.org/cpython/rev/5a983773c09a

      New changeset 2caf82aee7a4 by Victor Stinner in branch '3.2':
      Issue bpo-10914: Initialize correctly the filesystem codec when creating a new
      http://hg.python.org/cpython/rev/2caf82aee7a4

    22. vstinner commented on Apr 30, 2011

      @vstinner
      Member

      Victor, the fix needs to go into 3.2 as well.

      Oh, I thought that Modules/_testembed.c was only in 3.3. Anyway, it is a real bug in 3.2, and it is now fixed (I backported the 2 fixes in 3.2).

    23. merwok commented on Sep 3, 2011

      @merwok
      Member

      BTW, about this comment in the code:
      # XXX only tested under Unix checkouts
      It is possible to install the _testembed.c file alongside xxmodule.c and compile it at test time. To test under Windows, I’ve re-read your first patch using distutils and it’s not that long or hard to read after all.

    24. pitrou commented on Sep 4, 2011

      @pitrou
      MemberAuthor

      It is possible to install the _testembed.c file alongside xxmodule.c
      and compile it at test time.

      We probably could, using the approach from the distutils patch. But it feels really quirky to me. Granted, the Makefile is quirky as well.

      To test under Windows, I’ve re-read your first patch using distutils
      and it’s not that long or hard to read after all.

      Except that it didn't work under Windows...

    25. merwok commented on Sep 5, 2011

      @merwok
      Member

      Except that it didn't work under Windows...
      Ah. If it was an extension module, I’d have a clue (the debug thing), but I know nothing about embedding. An alternative would be to install the file with the msi system and use a project file to have it compiled (sounds like much hassle).

    26. pitrou commented on Sep 5, 2011

      @pitrou
      MemberAuthor

      Ah. If it was an extension module, I’d have a clue (the debug thing),
      but I know nothing about embedding. An alternative would be to
      install the file with the msi system and use a project file to have it
      compiled (sounds like much hassle).

      Agreed, but it's not something that I know how to do :)
      (and yet, of course, it would be good to test that embedding works under
      Windows too, as well as under Unix installs)

    27. transferred this issue fromon Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Metadata

    Metadata

    Assignees

    Labels

    interpreter-core(Objects, Python, Grammar, and Parser dirs)testsTests in the Lib/test dir

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions