Skip to content

test_signal cannot test blocked signals if _tkinter is loaded; Tcl_Finalize() #56207

Closed

Description

@vstinner
BPO 11998
Nosy @vstinner
PRs
  • bpo-11998: Patch smtplib.py #23490
  • Files
  • tkinter_finalize.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 = None
    closed_at = <Date 2011-05-24.15:17:33.573>
    created_at = <Date 2011-05-04.10:30:37.996>
    labels = ['tests', 'expert-tkinter']
    title = 'test_signal cannot test blocked signals if _tkinter is loaded; Tcl_Finalize()'
    updated_at = <Date 2020-11-24.10:52:50.999>
    user = 'https://github.com/vstinner'

    bugs.python.org fields:

    activity = <Date 2020-11-24.10:52:50.999>
    actor = 'python-dev'
    assignee = 'none'
    closed = True
    closed_date = <Date 2011-05-24.15:17:33.573>
    closer = 'vstinner'
    components = ['Tests', 'Tkinter']
    creation = <Date 2011-05-04.10:30:37.996>
    creator = 'vstinner'
    dependencies = []
    files = ['21882']
    hgrepos = []
    issue_num = 11998
    keywords = ['patch']
    message_count = 4.0
    messages = ['135109', '135111', '135113', '136754']
    nosy_count = 3.0
    nosy_names = ['vstinner', 'gpolo', 'python-dev']
    pr_nums = ['23490']
    priority = 'normal'
    resolution = 'wont fix'
    stage = None
    status = 'closed'
    superseder = None
    type = None
    url = 'https://bugs.python.org/issue11998'
    versions = ['Python 3.3']

    Activity

    1. vstinner commented on May 4, 2011

      @vstinner
      MemberAuthor

      I'm working on signals, especially on pthread_sigmask(), and I'm trying to understand test_signal failures.

      test_signal fails if the _tkinter module is loaded, because _tkinter loads the Tcl library which create a thread waiting events in select(). For example, "python -m test test_pydoc test_signal" fails, because test_pydoc loads ALL Python modules. I opened an issue for test_pydoc: http://bugs.python.org/issue11995

      _tkinter.c contains the following code:
      #if 0
          /* This was not a good idea; through <Destroy> bindings,
             Tcl_Finalize() may invoke Python code but at that point the
             interpreter and thread state have already been destroyed! */
          Py_AtExit(Tcl_Finalize);
      #endif

      Tcl_Finalize() exits the thread, but this function is never called in Python. Anyway, it is not possible to unload a module implemented in C.

      I would like to know if it would be possible to mask all signals in the Tcl thread, or if Tcl supports/uses signals.

      It is possible to mask all signals in the Tcl thread using:
      ----------

      allsignals = range(1, signal.NSIG)
      oldmask = signal.pthread_sigmask(signal.SIG_BLOCK, allsignals)
      import _tkinter
      signal.pthread_sigmask(signal.SIG_SETMASK, oldmask)

      I'm not asking the question for test_signal: I have a patch fixing test_signal, even if the Tcl zombi thread is present (use pthread_kill() to send the signal directly to the main thread).

      (I wrote "zombi" thread because I was not aware that Tcl uses a thread,
      nor that test_pydoc loads all modules. The thread is valid, alive, and
      it's just a joke. The threads is more hidden than zombi.)

      (Message copied/pasted from python-dev)

    2. python-dev commented on May 4, 2011

      python-devmannequin
      Mannequin

      New changeset 88dca05ed468 by Victor Stinner in branch 'default':
      Issue bpo-11998, issue bpo-8407: workaround _tkinter issue in test_signal
      http://hg.python.org/cpython/rev/88dca05ed468

    3. vstinner commented on May 4, 2011

      @vstinner
      MemberAuthor

      As suggested by Antoine, here is a patch to call Tcl_Finalize() in test_signal.

      You can call create a Tcl/Tk window, destroy it, call _tkinter._finalize(), and then create a new Tcl/Tk window. But call _tkinter._finalize() crashes if there is still a running Tcl/Tk window.

      We should add a safety test checking that there is no more running widget. If it is not possible to implement this, the function should only be compiled in debug mode. If it is possible, it would be nice to call _tkinter._finalize() when the last widget is destroyed and/or at Python exit.

    4. changed the title [-]test_signal cannot test blocked signals if _tkinter is loaded[/-] [+]test_signal cannot test blocked signals if _tkinter is loaded; Tcl_Finalize()[/+] on May 4, 2011
    5. vstinner commented on May 24, 2011

      @vstinner
      MemberAuthor

      I implemented signal.pthread_kill(), so it's now possible to test pending signals in test_signal, even if _tkinter is loaded.

      I don't think that we need the _finalize() hack anymore.

    6. 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

    No one assigned

      Labels

      Projects

      No projects

        Milestone

        No milestone

        Relationships

        None yet

        Development

        No branches or pull requests

        Issue actions