[Tutor] Reading in file and processing it in a thread
Vicki Stanfield
vicki at thepenguin.org
Fri Jul 23 21:22:28 CEST 2004
> #Test thread code
> thread2 = thread.start_new_thread(self.ThreadTest, ())
Okay, I have set this up as the above code calling this:
def ThreadTest(self):
print "Got into ThreadTest"
inputfile = self.filesel.GetFilename()
input = open('C:/'+inputfile, 'r')
tokens=""
while STOP_READ != wx.TRUE or first_iteration == wx.TRUE:
for line in input.readlines():
if len(line)>1:
first_iteration == wx.FALSE
tokens=line.split("|")
self.command = tokens[0][0]+tokens[0][1]
self.arguments = tokens[0].lstrip(tokens[0][0]+tokens[0][1]+" ")
print self.command
print self.arguments
self.ProcessCommand(self.command, self.arguments)
#wx.GetApp().Yield()
else:
input.close()
But I get a strange error:
Got into ThreadTest
Unhandled exception in thread started by <bound method ComboBoxPanel.ThreadTest
of <__main__.ComboBoxPanel instance; proxy of C++ wxPanel instance at _8296c0_wx
Panel_p>>
Traceback (most recent call last):
File "F:\wxComTool1.1.py", line 252, in ThreadTest
inputfile = self.filesel.GetFilename()
File "C:\Python23\Lib\site-packages\wxPython\wx.py", line 1834, in __getattr__
raise wxPyDeadObjectError( self.attrStr % self._name )
wxPython.wx.wxPyDeadObjectError: The C++ part of the wxFileDialog object has bee
n deleted, attribute access no longer allowed.
Can anyone explain to me what I am doing wrong? If this same code is included where the call to
start_new_thread is, it works except that I am unable to get back to the gui to uncheck the checkbox.
It needs to be a different thread, so what am I doing wrong?
Thanks,
--vicki
More information about the Tutor
mailing list