Hello,
I cannot seem to make a separate thread that will run forever. I create and run a thread at the end of the main constructor of class World(DirectObject), but control is passed indefinitely to this thread, and the world never renders.
I have tried thread, theading and threading2 from direct.stdpy using appropriate python semantics, but it always blocks the main thread.
The thread is just doing a
while(True):
time.sleep(1)
print “test”
it works fine (doesn’t block main thread), but obviously this is not going to work long term. Has anyone successfully used the panda version of python threads on OSX?
Well… seeing as you don’t understand how they work… I just want to say is: don’t use another thread unless it’s to help with IO blocking. At any case… most of panda 3d IO calling already has a way to over come the IO blocking.
But you have to tell the thread to .considerYield() do to it being inside a endless loop whitch is being called every cpu cycle.
What a completely unhelpful post. You do not just use concurrent methods for IO. You can (and should) use them for blocking network calls, or any processing that will take a while and tie up the main process.
Don’t post negative, unhelpful comments on forums please.
Helps get over the networking block IO calls… Again… no more threads are needed as this can be ran in a singal thread.
Not sure how my post wasn’t helpful by any means seeing as that should be that problem + answer.
Anyways… I was just giving you other options you can do instead of threading. If you don’t like what I had to say, then you don’t have to be so rude either.
I am not sure this is the best way to a conversation. If I knew how the Panda thread implementation worked, I wouldn’t be posting
I am hoping to be able to use my own networking and other code independent of panda3d for a variety of reasons.
Thank you for trying to help. I tried doing my_thread.considerYield() before calling start, but it still blocked the main process (not sure if this is what you meant).
I am also currently compiling the src with SIMPLE_THREADS set to 0 with the hopes that it will actually spawn an OS thread.
It would be great if the documentation for threading would include a few examples of how panda threads are intended to be used or not used.
using select, kqueue, or epoll would work, but feels like the wrong tool for the job here.
lol ok much better:) By the comment, I was just trying to save you from the head aces
Anyways:
#Loop
while(True):
#Sleep THIS thread -- You used sleep, but this tells the program to sleep and not the thread while this tells the thread to sleep instead.
Thread.sleep(0.5)
#Make sure main thread doesn't need focus
Thread.considerYield() #or Thread.forceYield()
#Print out our debug
print "test"
Awesome that makes much more sense, and works! So it seems these are not real threads because the networking call still blocks. I wonder if disabling simple threads would cause it to use real os threads?
Thanks for your help.
One thing to note, Thread from the direct.stdpy.threading import Thread doesnt actually have a sleep member, but doing
from pandac import PandaModules as pm
sleep = pm.Thread.sleep
.
.
.
while(True):
sleep(1)
.
.
.
worked. Ill look into using select tomorrow. Thanks again.