global interpreter lock not working as it should

Martin v. Loewis martin at v.loewis.de
Tue Jul 30 02:32:22 EDT 2002


anton wilson <anton.wilson at camotion.com> writes:

> The reason your code works is because you explicitly give up the CPU
> with the sleep calls. If you remove both time.sleep calls the results will 
> look like:

I see. Now, I take the modified script

import threading, time

def func1():
    for i in range(10):
        for k in range(10):
            pass
        print "FUNC1"

def func2():
    for i in range(10):
        for k in range(10):
            pass
        print "FUNC2"

t = threading.Thread(target=func1)
t.start()
func2()

This has no explicitly-blocking calls, and prints

FUNC2
FUNC2
FUNC1
FUNC2
FUNC1
FUNC2
FUNC1
FUNC2
FUNC1
FUNC2
FUNC2
FUNC2
FUNC2
FUNC2
FUNC1
FUNC1
FUNC1
FUNC1
FUNC1
FUNC1

So I still can't see your problem.

Regards,
Martin




More information about the Python-list mailing list