ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> wxPython-users
wxPython-users
RE: [wxPython-users] Do I need another thread ?
by Stanfield, Vicki {D167~Indianapolis} other posts by this author
Jul 22 2004 8:48PM messages near this date
Re: [wxPython-users] debugging C++ with wxPython | [wxPython-users] wx.ListItem.GetBackgroundColour() return (-1,-1,-1)
Okay, I decided it was time to dive into the thread module after all. I
used to have an EVT handler which called the following code (I know it
ain't pretty!):

------------
    def ReadInFile(self):        
        inputfile = self.filesel.GetFilename()
        input = open('C:/'+inputfile, 'r')
        tokens=""
        
        first_iteration = wx.TRUE
        #While not STOP_READ, iterate through lines in file
        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()
--------------------

Now I want to create a thread in which to run the looping so that the
gui is (relatively) independent and a button on it can be used to toggle
the STOP_READ flag. I think I need to yank most of the above code out
and run it as a thread. I added this and can run the thread with it:

        #Test thread code
        thread2 = thread.start_new_thread(self.ThreadTest, ())

so I can make the new thread start. Do I want the open and close of the
file in the new thread or should input be passed to the thread from
outside? If it should be passed in, how do I convert input to a tuple? I
have a lot of confusion on threads at this point, so I apoligize if this
simple threading exercise should be obvious to me. The examples that I
have seen via google haven't been close enough to help me.

Thanks,
vicki

---------------------------------------------------------------------
To unsubscribe, e-mail: wxPython-users-unsubscribe@[...].org
For additional commands, e-mail: wxPython-users-help@lists.wxwidgets.org

Privacy Policy | Email Opt-out | Feedback | Syndication
© ActiveState Software Inc. All rights reserved