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

Python 3.0 halts on shutdown when settrace is set #48966

Closed
fabioz mannequin opened this issue Dec 22, 2008 · 4 comments
Closed

Python 3.0 halts on shutdown when settrace is set #48966

fabioz mannequin opened this issue Dec 22, 2008 · 4 comments
Labels
interpreter-core (Objects, Python, Grammar, and Parser dirs) stdlib Python modules in the Lib dir type-crash A hard crash of the interpreter, possibly with a core dump

Comments

@fabioz
Copy link
Mannequin

fabioz mannequin commented Dec 22, 2008

BPO 4716
Nosy @pitrou, @fabioz
Superseder
  • bpo-3618: possible deadlock in python IO implementation
  • Files
  • tracing_test.py: Code showing halting problem on shutdown
  • 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 = None
    closed_at = <Date 2008-12-26.23:17:34.463>
    created_at = <Date 2008-12-22.11:09:05.874>
    labels = ['interpreter-core', 'library', 'type-crash']
    title = 'Python 3.0 halts on shutdown when settrace is set'
    updated_at = <Date 2008-12-26.23:17:34.462>
    user = 'https://github.com/fabioz'

    bugs.python.org fields:

    activity = <Date 2008-12-26.23:17:34.462>
    actor = 'pitrou'
    assignee = 'none'
    closed = True
    closed_date = <Date 2008-12-26.23:17:34.463>
    closer = 'pitrou'
    components = ['Interpreter Core', 'Library (Lib)']
    creation = <Date 2008-12-22.11:09:05.874>
    creator = 'fabioz'
    dependencies = []
    files = ['12422']
    hgrepos = []
    issue_num = 4716
    keywords = []
    message_count = 4.0
    messages = ['78169', '78174', '78315', '78316']
    nosy_count = 3.0
    nosy_names = ['ggenellina', 'pitrou', 'fabioz']
    pr_nums = []
    priority = 'normal'
    resolution = 'duplicate'
    stage = None
    status = 'closed'
    superseder = '3618'
    type = 'crash'
    url = 'https://bugs.python.org/issue4716'
    versions = ['Python 3.0']

    @fabioz
    Copy link
    Mannequin Author

    fabioz mannequin commented Dec 22, 2008

    In Python 3.0, the interpreter will not shutdown properly after setting
    a tracing function and something goes into stdout.

    The code attached shows the problem in action: just execute it and
    notice how the interpreter will be kept running after the code has been
    executed.

    There are some more things that need to be considered:

    • If the print('here') is not called, it will shutdown
    • If BOTH the print('here') and the sys.settrace(None) is not called, it
      will NOT shutdown

    Note: I've marked the bug as crash because it's halting, but maybe there
    could be a better alternative for it...

    @fabioz fabioz mannequin added interpreter-core (Objects, Python, Grammar, and Parser dirs) type-crash A hard crash of the interpreter, possibly with a core dump labels Dec 22, 2008
    @pitrou
    Copy link
    Member

    pitrou commented Dec 22, 2008

    I haven't investigated, but in py3k print() has currently bits written
    in Python, which means it will get (recursively) traced when called from
    the trace function. It can of course have all kinds of funny implications!

    @ggenellina
    Copy link
    Mannequin

    ggenellina mannequin commented Dec 26, 2008

    Yes, this is exactly the problem. The execution never goes beyond print
    ('here'); if you print frame.f_lineno you'll see it blocks at io.py
    line 1036, waiting for a Lock for the second time.

    So the trace function cannot use print, not write to regular files
    (because io.py is written in Python). This is a severe limitation.

    As a workaround, you can use the _fileio module (written in C):

    import _fileio
    f = _fileio._FileIO("output.txt", "w", True)
    
    def tracing_func(frame, event, arg):
        f.write('%s %s %d\n' % (frame.f_code.co_filename, frame.f_code.co_
    name, frame.f_lineno))
        return tracing_func

    A possible fix would be to use an RLock instead of a Lock object, but
    I haven't investigated it.

    @ggenellina ggenellina mannequin added the stdlib Python modules in the Lib dir label Dec 26, 2008
    @pitrou
    Copy link
    Member

    pitrou commented Dec 26, 2008

    Thanks for the investigation! The problem has already been reported in
    bpo-3618. Closing this one.

    @pitrou pitrou closed this as completed Dec 26, 2008
    @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
    Labels
    interpreter-core (Objects, Python, Grammar, and Parser dirs) stdlib Python modules in the Lib dir type-crash A hard crash of the interpreter, possibly with a core dump
    Projects
    None yet
    Development

    No branches or pull requests

    1 participant