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

import of site.py fails on startup #47529

Closed
rupole mannequin opened this issue Jul 4, 2008 · 17 comments
Closed

import of site.py fails on startup #47529

rupole mannequin opened this issue Jul 4, 2008 · 17 comments
Assignees

Comments

@rupole
Copy link
Mannequin

rupole mannequin commented Jul 4, 2008

BPO 3279
Nosy @brettcannon, @amauryfa, @avassalotti, @benjaminp
Files
  • import-site.patch
  • different_order.patch
  • make_modules_builtin.patch
  • make_modules_builtin2.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/benjaminp'
    closed_at = <Date 2008-09-05.23:27:32.154>
    created_at = <Date 2008-07-04.03:40:25.972>
    labels = ['deferred-blocker']
    title = 'import of site.py fails on startup'
    updated_at = <Date 2008-09-05.23:27:32.153>
    user = 'https://bugs.python.org/rupole'

    bugs.python.org fields:

    activity = <Date 2008-09-05.23:27:32.153>
    actor = 'benjamin.peterson'
    assignee = 'benjamin.peterson'
    closed = True
    closed_date = <Date 2008-09-05.23:27:32.154>
    closer = 'benjamin.peterson'
    components = []
    creation = <Date 2008-07-04.03:40:25.972>
    creator = 'rupole'
    dependencies = []
    files = ['11241', '11247', '11400', '11402']
    hgrepos = []
    issue_num = 3279
    keywords = ['patch', 'needs review']
    message_count = 17.0
    messages = ['69240', '69252', '71913', '71922', '71928', '71931', '71933', '71935', '71946', '71947', '71948', '72629', '72636', '72642', '72643', '72647', '72650']
    nosy_count = 5.0
    nosy_names = ['brett.cannon', 'amaury.forgeotdarc', 'rupole', 'alexandre.vassalotti', 'benjamin.peterson']
    pr_nums = []
    priority = 'deferred blocker'
    resolution = 'fixed'
    stage = None
    status = 'closed'
    superseder = None
    type = None
    url = 'https://bugs.python.org/issue3279'
    versions = ['Python 3.0']

    @rupole
    Copy link
    Mannequin Author

    rupole mannequin commented Jul 4, 2008

    In pythonrun.c, initstdio injects 'open' into builtins. However,
    initsite is called before initstdio and site.py uses open.
    Running with -v, this traceback is printed:

    Traceback (most recent call last):
      File "j:\python30\lib\site.py", line 518, in <module>
    main()
      File "j:\python30\lib\site.py", line 501, in main
    known_paths = addsitepackages(known_paths)
      File "j:\python30\lib\site.py", line 281, in addsitepackages
    addsitedir(sitedir, known_paths)
      File "j:\python30\lib\site.py", line 178, in addsitedir
    addpackage(sitedir, name, known_paths)
      File "j:\python30\lib\site.py", line 141, in addpackage
    f = open(fullname, "rU")
    NameError: global name 'open' is not defined

    @amauryfa
    Copy link
    Member

    amauryfa commented Jul 4, 2008

    This happens if the site-packages directory contains a .pth file.

    This was unnoticed because the usual message
    'import site' failed; use -v for traceback
    is never printed: sys.stderr is empty before the call to initstdio().

    @amauryfa
    Copy link
    Member

    Attached patch writes the "'import site' failed" message to libc stderr
    instead of sys.stderr, which does not exist at this point.

    The initial problem still remains: site.py cannot use the "open" builtin.

    @benjaminp
    Copy link
    Contributor

    We could:

    1. Use _fileio._FileIO directly.
    2. Use os.open.
    3. Initialize the stdio streams before importing site. This seems like
      the best option, although I haven't run all the tests yet.

    @benjaminp
    Copy link
    Contributor

    Here's my patch for the problem.

    @amauryfa
    Copy link
    Member

    Well, it would be interesting to know why r62778 has exactly the
    opposite move.
    Alexandre, do you remember doing it?

    @benjaminp
    Copy link
    Contributor

    It was probably done so that importing _bytesio would actually work in
    io. IMO, it would be better to just compile _bytesio and _stringio into
    the python binary.

    @avassalotti
    Copy link
    Member

    Benjamin is right. site.py imports the io module before _bytesio and
    _stringio are available for import. Thus the python version of BytesIO
    and StringIO is always used. There is an old thread about the issue at
    http://mail.python.org/pipermail/python-3000/2007-December/011569.html

    As for compiling _bytesio and _stringio into the main binary, you should
    ask python-dev or python-3000.

    @brettcannon
    Copy link
    Member

    On Mon, Aug 25, 2008 at 6:40 AM, Benjamin Peterson
    <report@bugs.python.org> wrote:

    Benjamin Peterson <musiccomposition@gmail.com> added the comment:

    We could:

    1. Use _fileio._FileIO directly.
    2. Use os.open.
    3. Initialize the stdio streams before importing site. This seems like
      the best option, although I haven't run all the tests yet.

    Or you could use _warnings which is already compiled into the binary.

    @benjaminp
    Copy link
    Contributor

    On Mon, Aug 25, 2008 at 12:48 PM, Brett Cannon <report@bugs.python.org> wrote:

    Brett Cannon <brett@python.org> added the comment:

    On Mon, Aug 25, 2008 at 6:40 AM, Benjamin Peterson
    <report@bugs.python.org> wrote:
    >
    > Benjamin Peterson <musiccomposition@gmail.com> added the comment:
    >
    > We could:
    >
    > 1. Use _fileio._FileIO directly.
    > 2. Use os.open.
    > 3. Initialize the stdio streams before importing site. This seems like
    > the best option, although I haven't run all the tests yet.
    >

    Or you could use _warnings which is already compiled into the binary.

    How would that help the problem of site using open() when it can't?


    Python tracker <report@bugs.python.org>
    <http://bugs.python.org/issue3279\>


    --
    Cheers,
    Benjamin Peterson
    "There's no place like 127.0.0.1."

    @brettcannon
    Copy link
    Member

    On Mon, Aug 25, 2008 at 10:49 AM, Benjamin Peterson
    <report@bugs.python.org> wrote:
    >
    > Benjamin Peterson <musiccomposition@gmail.com> added the comment:
    >
    > On Mon, Aug 25, 2008 at 12:48 PM, Brett Cannon <report@bugs.python.org> wrote:
    >>
    >> Brett Cannon <brett@python.org> added the comment:
    >>
    >> On Mon, Aug 25, 2008 at 6:40 AM, Benjamin Peterson
    >> <report@bugs.python.org> wrote:
    >>>
    >>> Benjamin Peterson <musiccomposition@gmail.com> added the comment:
    >>>
    >>> We could:
    >>>
    >>> 1. Use _fileio._FileIO directly.
    >>> 2. Use os.open.
    >>> 3. Initialize the stdio streams before importing site. This seems like
    >>> the best option, although I haven't run all the tests yet.
    >>>
    >>
    >> Or you could use _warnings which is already compiled into the binary.
    >
    > How would that help the problem of site using open() when it can't?
    >>

    Sorry, replied to the wrong email. It was meant as a reply to Amaury's
    suggestion of writing out a comment that importing site failed to
    stderr.

    @benjaminp
    Copy link
    Contributor

    IMO, it's unacceptable to be running Python code before the stdio
    streams are set up. I believe that moving the site initialization after
    the setting up the streams isn't as big a problem because the dynlibs
    are on sys.path before site is run when python is installed. See
    bpo-586680. I will write to Python-dev.

    @benjaminp
    Copy link
    Contributor

    Here's a patch that builds _bytesio and _stringio right into the binary.
    I think Windows build files will need to be updated, though.

    @amauryfa
    Copy link
    Member

    amauryfa commented Sep 5, 2008

    Windows build files will need to be updated
    Nothing to do here: they are already built-in, linked into Python30.dll,
    and listed in PC/config.c

    But shouldn't the two extension modules be removed from setup.py?

    @benjaminp
    Copy link
    Contributor

    Yes, indeed.

    @avassalotti
    Copy link
    Member

    Look good to me, and python-dev accepted the patch. So, go ahead and
    commit it.

    @benjaminp
    Copy link
    Contributor

    Fixed in r66239.

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Projects
    None yet
    Development

    No branches or pull requests

    4 participants