TextNode and threading?

The concept idea: Have hundreds of constantly changing TextNode’s on the screen, all at once.

The main problem: Calls to TextNode.generate() are very expensive.

The possible solution? Is there a way for Panda to run all TextNode.generate() calls in a seperate thread? I’ve attempted doing it on my own using direct.stdpy.threading.Thread, only it causes dead locks, I would guess this is to my own lack of knowledge.

could anyone help me?

Well I appear to have found a semi-solution, the following code does work, however produces some strange visual artifacts with text (particularly some characters randomly flashing) which I’m okay with for now.

from panda3d.core import *
loadPrcFileData('', 'support-threading #t')
import direct.directbase.DirectStart
from direct.stdpy.threading import Thread
import random

np = render.attachNewNode('my-text-np')
tn = TextNode("my-text-node")

t = taskMgr.setupTaskChain("text-generation", numThreads=1)

def updateTheText(task):
    global np
    print "Updating the text.."
    np = render.attachNewNode(tn.generate())
    print "Done."
    return task.cont

def startUpdate():
    taskMgr.add(updateTheText, 'updateTheText', taskChain='text-generation')

base.accept('1', startUpdate)
print "Press 1 ONLY once"


Regardless of how you touch it, threading is a large scary beast, and I highly advise anyone and everyone to only touch it when you’re absolutely sure it’s required.

Let’s call this one semi-solved as say that TextNode has some issues with threading that are hard to reproduce.