Thread for a newbie

J

JDevine

Hi. I have just finished my first python program. Unfortunately
threading has me stumped. I think this is mostly because the
wx.thread example demo is very complex, with all the grahphics,
graphs, and draw functions. I want to do something very simple. My
program downloads files over HTTP, I want to instantiate a process
dialog that tracks the download. I already have access to the
expected size of each file through other functions in my program, I
also assume an os.foo is capable of getting the current size as the
file grows as it is downloaded. My issue is keeping the file
downloading WHILE it is being tracked by the process dialog. Please
help with any simple thread examples you might have, if this example
includes a dialog even better.
Thanks for any help you can provide.

-Justin
(e-mail address removed) thanks
 
T

Tom B.

JDevine said:
Hi. I have just finished my first python program. Unfortunately
threading has me stumped. I think this is mostly because the
wx.thread example demo is very complex, with all the grahphics,
graphs, and draw functions. I want to do something very simple. My
program downloads files over HTTP, I want to instantiate a process
dialog that tracks the download. I already have access to the
expected size of each file through other functions in my program, I
also assume an os.foo is capable of getting the current size as the
file grows as it is downloaded. My issue is keeping the file
downloading WHILE it is being tracked by the process dialog. Please
help with any simple thread examples you might have, if this example
includes a dialog even better.
Thanks for any help you can provide.

-Justin
(e-mail address removed) thanks

Don't use the wxPython threading example, use instead the threading module
from the standard library. It is vey easy to use and works fine with
wxPython.

Tom
 
B

Beeyah

Hi. I have just finished my first python program. Unfortunately
threading has me stumped. I think this is mostly because the
wx.thread example demo is very complex, with all the grahphics,
graphs, and draw functions. I want to do something very simple. My
program downloads files over HTTP, I want to instantiate a process
dialog that tracks the download. I already have access to the
expected size of each file through other functions in my program, I
also assume an os.foo is capable of getting the current size as the
file grows as it is downloaded. My issue is keeping the file
downloading WHILE it is being tracked by the process dialog. Please
help with any simple thread examples you might have, if this example
includes a dialog even better.
Thanks for any help you can provide.

-Justin
(e-mail address removed) thanks

import threading # not thread

# to make your thread,
# inherit the thread.Threading class, then
# override the __init__ and run methods to define
# what your thread is actually going to do, like so:

class MyNewThread( threading.Thread ):
def __init__( self , argument ):
# generally speaking, the first argument of every
# method should be self. in __init__'s case, the
# following arguments are the values passed into the
# thread upon creation, like so:
# handle = MyNewThread( 1 )
# in this case, this will define the var 'argument' as '1'
# to make these values accessible to the other methods,
# make it an attribute of self
self.arg = argument
# at the end of init you should always call the following:
thread.Threading.__init__( self )
def run( self ):
# this function is called once you call MyNewThread.start()
# once run() terminates, the thread goes with it. so just
# define what you want your thread to do in this function.
print repr( self.arg ) + " foo bar"
# noteably useless

handle = MyNewThread( 2832 )
handle.start() # now the thread's run() method is running

Its important to note that, with the exception of the Queue object,
manipulating an object by the hands of multiple threads is dangerous,
and isn't recommended.

if i messed something up someone correct me, thanks.

Beeyah
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,294
Messages
2,571,511
Members
48,216
Latest member
DarrelLho

Latest Threads

Top