1

i am learning multi-threading in python and used following code from the following link.

http://www.tutorialspoint.com/python/python_multithreading.htm

The Pythonwin IDE hangs (not responding) for more than 30 min, Please help me if there is some problem in the code.

import thread import time # Define a function for the thread def print_time( threadName, delay): count = 0 while count < 5: time.sleep(delay) count += 1 print "%s: %s" % ( threadName, time.ctime(time.time()) ) # Create two threads as follows try: thread.start_new_thread( print_time, ("Thread-1", 2, ) ) thread.start_new_thread( print_time, ("Thread-2", 4, ) ) except: print "Error: unable to start thread" while 1: pass 
0

2 Answers 2

1

Remove the last code:

while 1: pass 

It makes your code running forever ,so your ide won't response anymore. If you want to wait these threads until run over,you can add time.sleep(35) at last to wait.

Sign up to request clarification or add additional context in comments.

Comments

1

The program will never finish. Your program will write 5 times the data for each thread and then just hang forever on the main thread.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.