Im trying to use a another thread in python but as soon as another python script get called Blender 2.49b just stop running the thread… why? dunno…
How can I get around this bug?
To reproduce it:
Start the following script and monitor the console:
import thread
from thread import *
def thread_callback(num, *args):
while( 1 ):
num = num + 1
print num
test = 0
thread.start_new_thread( thread_callback, (test,1) )
Start another script ie in the 3D viewport
Space Bar -> Add -> Mesh -> Torus
As soon as the Torus script GUI appear the thread will just stop… and its impossible to restart it even if the script is executed again… Any “known” work around?
I am successfully using threading module with and without the blender gui.
give this a shot.
import threading
class ThreadRunner(threading)
def init(self):
self.thread.init(target=self.target,args=[])
self.start()
self.needed=1
self.inc=0
self.queue=[]
def target(self):
while(self.needed):
time.sleep(1)
self.inc+=1
aCmd=self.queue.pop()
if (aCmd):
exec(aCmd)
Once again to reproduce the bug that cause the thread to just start hanging somewhere try the following:
Run the script
Start ANY other python script from within Blender v2.49
Ex:
3D View -> Space Bar -> Add -> Mesh -> EmptyMesh
The thread will just stop printing the time and will never come back to life until you .join() it back to the main thread… If you query with enumerate() you will see that the thread is there, started and alive… Its just hanging, frozen somewhere… Very weird…
import threading
for t in threading.enumerate():
print t
print t.isAlive()
print
I really hope that someone can help me on this Im stuck and currently can’t go forward until this is fixed…
I think the blender program is flushing stdout, hence why you dont see anything "print"ed from python, use sys.stderr
I remember its the only reliable way of printing out of a python script. Also if your starting the program with -P <script> there is a lot of problem’s I have encountered.
Actually this is a problem with the console that is written in the blender processing fashion, running threads works fine if you start them with blender, This does have some drawbacks , example:
I think the blender program is flushing stdout, hence why you dont see anything "print"ed from python, use sys.stderr
No dude, I can guarantee you at 100% certainty that the thread is not running, it is simply frozen and hanging somewhere… Try my test up there, simply remember the last number printed, mess around with other scripts to force to get another output and you’ll see… The thing is I test that with a TCP connection, and when this happen the server doesn’t receive anything, hence my conclusion that it is frozen.