What is wrong with my Python threading?

C

Chuckk Hubbard

#!/usr/bin/python

#why doesn't this run both threads simultaneously?
#Thanks for any help.
#Chuckk

import threading
import time

def printesc(thrd):
for i in range(10):
time.sleep(1)
print thrd, i

def master():
thd1 = threading.Thread(target=printesc, args=(1,))
thd2 = threading.Thread(target=printesc, args=(2,))
thd1.run()
thd2.run()

master()
 
C

castironpi

#!/usr/bin/python

#why doesn't this run both threads simultaneously?
#Thanks for any help.
#Chuckk

import threading
import time

def printesc(thrd):
    for i in range(10):
        time.sleep(1)
        print thrd, i

def master():
    thd1 = threading.Thread(target=printesc, args=(1,))
    thd2 = threading.Thread(target=printesc, args=(2,))
    thd1.run()
    thd2.run()

master()

You meant 'thd1.start( )' and 'thd2.start( )'.
 
D

Diez B. Roggisch

Chuckk said:
#!/usr/bin/python

#why doesn't this run both threads simultaneously?
#Thanks for any help.
#Chuckk

Because you should call thread.start().


Diez
 
G

Gabriel Genellina

You meant 'thd1.start( )' and 'thd2.start( )'.

Wow! A message with a high S/N ratio coming from you!
And it's not the first I've seen - whatever pills you're taking, they're
good for you...
 
E

Eduardo O. Padoan

Wow! A message with a high S/N ratio coming from you!
And it's not the first I've seen - whatever pills you're taking, they're
good for you...

This is why I shouldn't be so eager adding people to the killfile.
 
C

Chuckk Hubbard

You meant 'thd1.start( )' and 'thd2.start( )'.

So I did. I was mixing what I read of thread and threading. I'll
never wander beyond my Python module reference html folder again.
Thanks for your help.

-Chuckk
 

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

Forum statistics

Threads
474,212
Messages
2,571,101
Members
47,695
Latest member
KayleneBee

Latest Threads

Top