no parallel threading?

Roman Suzi rnd at onego.ru
Wed Sep 5 14:05:27 EDT 2001


On Wed, 5 Sep 2001, Tobias Unruh wrote:

>Hi,
>
>I tried to execute two threads in parallel (linux 2.4.9, python 2.0):
>
>import time
>import threading
>
>def test_thread_func1():
>    print "Hallo1"
>    time.sleep(3.0)
>    print "Hallo1"
>
>def test_thread_func2():
>    print "Hallo2"
>    time.sleep(3.0)
>    print "Hallo2"
>
>printlock = threading.Lock()
>
>test_thread1 = threading.Thread(None,test_thread_func1())
>test_thread2 = threading.Thread(None,test_thread_func2())

>Why this result? From the first four lines I concluded that the threads
>are executed one after the other (which is not intended). In this case,
>however, the number of active threads should be 1 in any case. But these
>values are ok. Is there something wrong with the output?
>sys.stdout.flush() does not help.

Your computer is too fast. Try cycling in test_funcs and use random
sleep times (I even think, that you need delay loops: I am not sure
what happens when you issue sleep. Probabbly the whole process sleeps.
Then (probably) you will get intermingled strings.

BTW, this is what intrigued Linus most and was supported from the very
first version of Linux ;-) (in processes, of course, not threads)


Sincerely yours, Roman Suzi
-- 
_/ Russia _/ Karelia _/ Petrozavodsk _/ rnd at onego.ru _/
_/ Wednesday, September 05, 2001 _/ Powered by Linux RedHat 6.2 _/
_/ "... Clinton sandwich: $5 of baloney and $20 in taxes" _/





More information about the Python-list mailing list