classification
Title: tkinter goes into an infinite loop (pydoc.gui)
Type: crash Stage:
Components: Extension Modules Versions: Python 3.0
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: HWJ, gpolo (2)
Priority: normal Keywords patch

Created on 2008-09-11 13:20 by HWJ, last changed 2008-09-17 13:10 by gpolo.

Files
File name Uploaded Description Edit Remove
issue_3835.diff gpolo, 2008-09-17 13:08
Messages (9)
msg73021 - (view) Author: Helmut Jarausch (HWJ) Date: 2008-09-11 13:20
With version 3.0 (SVN 66386)

import pydoc
pydoc.gui()

gives

>>> Exception in thread Thread-1:
Traceback (most recent call last):
  File "/usr/local/lib/python3.0/threading.py", line 507, in 
_bootstrap_inner
    self.run()
  File "/usr/local/lib/python3.0/threading.py", line 462, in run
    self._target(*self._args, **self._kwargs)
  File "/usr/local/lib/python3.0/pydoc.py", line 1989, in serve
    DocServer(port, callback).serve_until_quit()
  File "/usr/local/lib/python3.0/pydoc.py", line 1971, in __init__
    self.base.__init__(self, self.address, self.handler)
  File "/usr/local/lib/python3.0/socketserver.py", line 401, in __init__
    self.server_activate()
  File "/usr/local/lib/python3.0/pydoc.py", line 1982, in 
server_activate
    if self.callback: self.callback(self)
  File "/usr/local/lib/python3.0/pydoc.py", line 2072, in ready
    text='Python documentation server at\n' + server.url)
  File "/usr/local/lib/python3.0/tkinter/__init__.py", line 1199, in 
configure
    return self._configure('configure', cnf, kw)
  File "/usr/local/lib/python3.0/tkinter/__init__.py", line 1190, in 
_configure
    self.tk.call(_flatten((self._w, cmd)) + self._options(cnf))
_tkinter.TclError: out of stack space (infinite loop?)
msg73237 - (view) Author: Guilherme Polo (gpolo) Date: 2008-09-14 21:33
What tcl/tk version are you using ?

Also, can you put a "print(_flatten((self._w, cmd)) +
self._options(cnf))" before the line 1190 in
/usr/local/lib/python3.0/tkinter/__init__.py and tell what it shows when
you call pydoc.gui ?
msg73259 - (view) Author: Helmut Jarausch (HWJ) Date: 2008-09-15 12:50
I'm using Tcl/Tk  8.5.4  here

        print(":::")
        print(_flatten((self._w, cmd)) + self._options(cnf))

produces:
:::
('.3073836300', 'configure', '-yscrollcommand', '3077632332set')
:::
('.3073835564.3073835660', 'configure', '-text', 'Python documentation 
server at\nhttp://localhost:7464/')
>>> Exception in thread Thread-1:
Traceback (most recent call last):
  File "/usr/local/lib/python3.0/threading.py", line 507, in 
_bootstrap_inner
    self.run()
  File "/usr/local/lib/python3.0/threading.py", line 462, in run
    self._target(*self._args, **self._kwargs)
  File "/usr/local/lib/python3.0/pydoc.py", line 1989, in serve
    DocServer(port, callback).serve_until_quit()
  File "/usr/local/lib/python3.0/pydoc.py", line 1971, in __init__
    self.base.__init__(self, self.address, self.handler)
  File "/usr/local/lib/python3.0/socketserver.py", line 401, in __init__
    self.server_activate()
  File "/usr/local/lib/python3.0/pydoc.py", line 1982, in 
server_activate
    if self.callback: self.callback(self)
  File "/usr/local/lib/python3.0/pydoc.py", line 2072, in ready
    text='Python documentation server at\n' + server.url)
  File "/usr/local/lib/python3.0/tkinter/__init__.py", line 1201, in 
configure
    return self._configure('configure', cnf, kw)
  File "/usr/local/lib/python3.0/tkinter/__init__.py", line 1192, in 
_configure
    self.tk.call(_flatten((self._w, cmd)) + self._options(cnf))
_tkinter.TclError: out of stack space (infinite loop?)
msg73265 - (view) Author: Guilherme Polo (gpolo) Date: 2008-09-15 15:29
Uhm, is it caused only by the combination of tk 8.5.4 and py3k, or does
the same happen with tk 8.5.4 and python-trunk ? What about tk 8.5.3 (or
some other of tk 8.5 series) or even tk 8.4.16 and {python-trunk, py3k} ? 

It would be good if you could test some other combination, specially
because I can't reproduce it here with other versions (but I'm compiling
8.5.4 here now).
msg73302 - (view) Author: Guilherme Polo (gpolo) Date: 2008-09-16 15:18
Just reproduced the issue under python-trunk with tcl/tk 8.5.4 and 8.5.3
msg73303 - (view) Author: Guilherme Polo (gpolo) Date: 2008-09-16 15:41
But it happens only if you don't build tcl/tk with --enable-threads =)
msg73304 - (view) Author: Guilherme Polo (gpolo) Date: 2008-09-16 17:00
If you remove the widget.config calls in GUI.ready you will notice the
problem "goes away", but note that this method is called from another
thread while you have a non-thread-safe tcl/tk lib (I'm assuming you
didn't compile it with --enable-threads). So.. using multiple threads in
Python while Tcl is compiled without --enable-threads isn't supported at
all.

To reproduce the problem try this (change Tkinter to tkinter if py3k):


import threading
import Tkinter

lbl = Tkinter.Label(text="hi")
threading.Thread(target=lambda: lbl.configure(text="hi there")).start()
lbl.mainloop()


If your tcl/tk libs weren't compiled with --enable-threads this should
get you an "TclError: out of stack space (infinite loop?)". A
documentation note may be added somewhere, but nothing much else is
going to happen (that is what I believe at least).
msg73324 - (view) Author: Helmut Jarausch (HWJ) Date: 2008-09-17 08:07
Many thanks, that solved the problem.

Since the cause of the problem wasn't easy to find out
(for me, at least)

would be possible to check at import time if Tcl/Tk has been
configured with threads enabled?

Helmut.
msg73332 - (view) Author: Guilherme Polo (gpolo) Date: 2008-09-17 13:08
The patch attached checks for that when an interpreter is created, not
really at import time but should be enough.

But my real concern is that tkinter thinks it will work properly when
Python is using threads and Tcl wasn't compiled with --enable-threads.
Maybe that was true some time ago or maybe in other platforms, but isn't
the case anymore.
History
Date User Action Args
2008-09-17 13:10:11gpolosetpriority: normal
2008-09-17 13:08:48gpolosetfiles: + issue_3835.diff
keywords: + patch
messages: + msg73332
2008-09-17 08:07:43HWJsetmessages: + msg73324
2008-09-16 17:00:02gpolosetmessages: + msg73304
2008-09-16 15:41:20gpolosetmessages: + msg73303
2008-09-16 15:18:44gpolosetmessages: + msg73302
2008-09-15 15:29:26gpolosetmessages: + msg73265
2008-09-15 12:50:48HWJsetmessages: + msg73259
2008-09-14 21:33:52gpolosetnosy: + gpolo
messages: + msg73237
2008-09-11 13:20:28HWJcreate