Newbie having issues with threads



I'm a newbie trying to write a script that uses threads. I'm right
now a little bit stuck in understanding why the code snippet I wrote
doesn't seem to be entering the function defined in the
start_new_thread() call.

If I run it as is (the threaded version), the output is:

UA_1 configuring...
UA_1 halting..

But if I comment out the line w/ the thread and just call the function
directly, everything seems to work OK:

UA_1 configuring...
UA_1 executing...
UA_1 halting...

Can anyone tell me why the thread doesn't seem to invoke the function
"execute()"? I'm running Python 2.4.3.

Here is my code:

===========
import thread

class Test(object):
def __init__(self, instanceID):
self.instanceID = instanceID
def configure(self):
print self.instanceID + " configuring..."
def execute(self):
print self.instanceID + " executing..."
def halt(self):
print self.instanceID + " halting..."

if __name__ == "__main__":
"""usage: sipp_auto [options]"""

ua1 = Test("UA_1")

ua1.configure()

#ua1.execute()
thread.start_new_thread(ua1.execute, ())

ua1.halt()

===========
Thanks, James
.



Relevant Pages

  • use of "return"
    ... From my understanding, it can be avoided in a ... lot of cases since ruby returns the last value by default. ... Here's a code snippet from the SaltedHash Engine ... def authenticate ...
    (comp.lang.ruby)
  • Re: how to determine if files are on same or different file systems
    ... def moveMovieAndThumb: ... with Python's powerful exception handling mechanism you need not fear the ... failure of a particular code snippet, as long as you provide the ... Use methods of the str object rather than functions in the string module, ...
    (comp.lang.python)
  • Re: Newbie having issues with threads
    ... a little bit stuck in understanding why the code snippet I wrote doesn't ... seem to be entering the function defined in the start_new_threadcall. ... def configure: ... finishing its work first). ...
    (comp.lang.python)
  • Re: define_method and instance variable maddness
    ... I'm just cutting my teeth on metaprogramming but am stuck referencing ... Here's the code snippet in question. ... def add_personnel ... use eval if it makes the code easier to maintain. ...
    (comp.lang.ruby)
  • RE: MDI Tooltip Problem
    ... help us reproduce this problem on our side for better understanding? ... we input, so if we input "this is \n a test" in PropertyBrowser, we will ... get "this is\\n a test" in the generated code snippet. ...
    (microsoft.public.dotnet.languages.vb)