By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,889 Members | 1,259 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,889 IT Pros & Developers. It's quick & easy.

Tk and raw_input segfault

P: n/a
Python newbie disclaimer on

I am running an app with Tkinter screen in one thread and command-line
input in another thread using raw_input(). First question - is this
legal, should it run without issue? If not can you point me to a
description of why.

While updating objects on the screen I get a segfault after an
indeterminate number of updates. It doesn't seem to matter how quickly
the updates occur, but it does segfault faster when there are more
objects on the screen ( as I said failure time seems to have a random
factor added to it ).

Commenting out the raw_input() makes problem go away. I can schedule
as many updates as I wish without error. And it doesn't seem to matter
if I actually hit any keys for raw_input(), it can just sit there.

I have read other posts about readline library failures with Esc O M
sequences and could not recreate those failures.

This happens on 2 separate machines

1st: development workstation
tk-8.4.6-28
tcl-8.4.6-23
Python 2.3.3 (#1, Feb 5 2005, 16:30:27)
[GCC 3.3.3 (SuSE Linux)] on linux2
Linux <name deleted> 2.6.5-7.151-smp #1 SMP Fri Mar 18 11:31:21 UTC
2005 x86_64 x86_64 x86_64 GNU/Linux

2nd: target machine
tk-8.4.6-37
tcl-8.4.6-26
Python 2.3.3 (#1, Apr 6 2004, 01:47:39)
[GCC 3.3.3 (SuSE Linux)] on linux2
Linux <name deleted> 2.6.4-52-default #1 Wed Apr 7 02:08:30 UTC 2004
i686 i686 i386 GNU/Linux

I have tried to simplify the code as much as possible to make error
more visible( no actual updates of the screen etc ) I've uncommented
the "after" code line so it fails much more rapidly. I know its ugly
repeatedly scheduling the after but, the same code runs without the
raw_input, and it shows the error more readily.

To see the error start the code and click the button repeatedly until
it segfaults. It will still segfault if you remove the 'command'
funtion and call update dirctly - it just takes a bit longer and your
wrist will probably get tired.

Thanks in advance for any responses.
------------------------------------------

from Tkinter import *
from time import sleep
import thread

class Test(Frame):
def __init__(self, parent=None):
Frame.__init__(self, parent, bg='white')

# Button Definition: CLEAR ALL OUTPUTS
caB = Button( self, text='CLEAR ALL\nOUTPUTS',\
#command = (lambda: self.update()) )
command = (lambda: self.command()) )
caB.pack()
self.updateCount = 0
self.commanded = 0
self.update()

def command( self ):
self.commanded = 1
self.update()

def update( self ):
self.updateCount += 1
print 'updatin... num = ', self.updateCount
self.after( 1, self.update )

def test():
root = Tk()
root.geometry('640x480')
Test().pack()
root.mainloop()

if __name__ == '__main__':
scanTID= thread.start_new_thread( test, () )
sleep(1)

while True:
f= raw_input()
print 'f=', f
sleep(1)

Jul 19 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.