[Bf-python] Blender Python & Threading?

Toni Alatalo antont at kyperjokki.fi
Tue Jun 16 21:43:38 CEST 2009


On Jun 16, 2009, at 10:23 PM, joe wrote:

> Ok, so technically it's normal threads, that are serialized via the
> GIL.  That's just semantics though :)

well on a single core machine they work like normal threads, are not 
'serialized' in that sense.

> I believe you have to explicitly release the GIL (and reacquire it) in
> the main thread for threads to really work at all.  What happens, is
> that the extra threads only get run when a python script gets events,
> and is pretty much dead the rest of the time.

i don't think that's true, doesn't the os switch between the threads 
being executed .. also within bpython. at least that's what i thought 
it was doing when tested them for some networking thing ages ago.

tested now and it does work, http://an.org/blender/thread.py source and 
how it execs in blender below too:

import threading, time

def hello():
	print "Hello!"
	
t = threading.Timer(5, hello)
t.start()

for i in range(10):
	print i
	time.sleep(1)	
	
"""prints:
0
1
2
3
4
Hello!
5
6
7
8
9
"""

GIL just means it doesn't use multiple processors for that within a 
single process.

~Toni




More information about the Bf-python mailing list