random
random

Reputation: 253

Can't get simple Python threading to work

I am new to threading (though not a beginner in Python) and I am having trouble making a thread work. I have the following simpl(est) program, but I cannot seem to get the function do_something() called. I must be doing something very basic wrong. Can anyone tell me what? Thanks a ton!

import threading

def do_something():
    print 'Function called...'

t = threading.Thread(target=do_something)

Of course, I had unwittingly previously deleted the t.start() instruction (Damn you Synaptic touchpad!!!!!!)

Upvotes: 0

Views: 104

Answers (2)

Marco L.
Marco L.

Reputation: 1499

you need to start your thread:

t.start()

Upvotes: 1

iurisilvio
iurisilvio

Reputation: 4987

You should start the thread:

import threading

def do_something():
    print 'Function called...'

t = threading.Thread(target=do_something)
t.start() # you forgot this line

Upvotes: 5

Related Questions