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

Signals discard one level of exception handling #38854

Closed
d-maurer mannequin opened this issue Jul 15, 2003 · 5 comments
Closed

Signals discard one level of exception handling #38854

d-maurer mannequin opened this issue Jul 15, 2003 · 5 comments
Labels
interpreter-core (Objects, Python, Grammar, and Parser dirs)

Comments

@d-maurer
Copy link
Mannequin

d-maurer mannequin commented Jul 15, 2003

BPO 771429
Nosy @mwhudson, @facundobatista, @d-maurer
Files
  • 771429.py: mwh's failed attempt to reproduce
  • 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 2005-01-15.21:26:40.000>
    created_at = <Date 2003-07-15.06:57:57.000>
    labels = ['interpreter-core']
    title = 'Signals discard one level of exception handling'
    updated_at = <Date 2005-01-15.21:26:40.000>
    user = 'https://github.com/d-maurer'

    bugs.python.org fields:

    activity = <Date 2005-01-15.21:26:40.000>
    actor = 'facundobatista'
    assignee = 'none'
    closed = True
    closed_date = None
    closer = None
    components = ['Interpreter Core']
    creation = <Date 2003-07-15.06:57:57.000>
    creator = 'dmaurer'
    dependencies = []
    files = ['966']
    hgrepos = []
    issue_num = 771429
    keywords = []
    message_count = 5.0
    messages = ['17064', '17065', '17066', '17067', '17068']
    nosy_count = 3.0
    nosy_names = ['mwh', 'facundobatista', 'dmaurer']
    pr_nums = []
    priority = 'normal'
    resolution = 'wont fix'
    stage = None
    status = 'closed'
    superseder = None
    type = None
    url = 'https://bugs.python.org/issue771429'
    versions = []

    @d-maurer
    Copy link
    Mannequin Author

    d-maurer mannequin commented Jul 15, 2003

    Signals handled by Python (especially KeyboardInterrupt)
    may discard one level of exception handling.

    Consider the following code fragment:

    try: # outer exception handling level
    try: # inner exception handling level
    blocking_external_extension_function()
    except:
    print "inner exception handling"
    except:
    print "outer exception handling"

    Assume that "blocking_external_extension_function"
    is an external function (implemented in "C") that
    blocks until interrupted by a signal (EINTR) and
    then returns with an exception but without handling
    the signal. In our concrete case,
    "blocking_external_extension_function" has been
    "psycopg.connect" (the database "connect" from the
    Python-PostgreSQL bridge "psycopg").

    In this case, when you interrupt the execution,
    while "blocking_external_extension_function"
    waits, the "KeyboardInterrupt" is not caught in
    the inner "try: ...except: ..." but only in the outer
    "try: ... except: ..."

    The following happens in detail in Python's main
    interpreter loop:

    • "blocking_external_extension_function" returns with
      an exception.

    • Python sets the next instruction to the exception
      handler of the inner exception handling

    • Python begins a new run through its main loop.
      At the start, it detects the "KeyboardInterrupt"
      signal. It now thinks, the "KeyboardInterrupt" were
      caused inside the inner exception handler
      and pops this exception handling level without
      executing it.

      The interpreter has lost one level of exception
      handling.

    The behaviour would probably better fit with expectations,
    when the interpreter would check for signals at the end of
    its main loop and before it sets its instruction pointer to the
    exception handler.

    @d-maurer d-maurer mannequin closed this as completed Jul 15, 2003
    @d-maurer d-maurer mannequin added the interpreter-core (Objects, Python, Grammar, and Parser dirs) label Jul 15, 2003
    @d-maurer d-maurer mannequin closed this as completed Jul 15, 2003
    @d-maurer d-maurer mannequin added the interpreter-core (Objects, Python, Grammar, and Parser dirs) label Jul 15, 2003
    @facundobatista
    Copy link
    Member

    Logged In: YES
    user_id=752496

    Please, could you verify if this problem persists in Python 2.3.4
    or 2.4?

    If yes, in which version? Can you provide a test case?

    If the problem is solved, from which version?

    Note that if you fail to answer in one month, I'll close this bug
    as "Won't fix".

    Thank you!

    . Facundo

    @mwhudson
    Copy link

    mwhudson commented Nov 9, 2004

    Logged In: YES
    user_id=6656

    In addition, attaching any code samples rather than including them
    would seem a good idea. I can't make head or tail of the code in
    the summary.

    @mwhudson
    Copy link

    mwhudson commented Nov 9, 2004

    Logged In: YES
    user_id=6656

    Oh, after some judicious view-sourcing and query-replacing, I get
    the problem. However, I can't reproduce it (see attached script).

    So we're back to needing a failing example and more platform
    details.

    @facundobatista
    Copy link
    Member

    Logged In: YES
    user_id=752496

    Deprecated. Reopen only if still happens in 2.3 or newer.

    . Facundo

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 9, 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)
    Projects
    None yet
    Development

    No branches or pull requests

    2 participants