Python Node Executing Twice (R20.059 Bug?)
-
Hi,
I'm trying to create a toggle function using a custom user data.
The problem is the Python Node in the Node Editor executes the function twice.
For this reason, I am stuck on perpetual loop.You can see an illustration file here:
https://www.dropbox.com/s/zn56e8tc5u7jn6c/c4d120_python_node_execute_twice.c4d?dl=0If you press the Print Me (the Toggle Button), it prints "Hello World" twice. You can also see the Mode A changing to Mode B then going back to Mode A again.
I labeled as a "bug" since I don't recall a similar behavior in R19.
Can you confirm? Thank you
-
Hi, @bentraje I can indeed confirm the change of behavior since R20 SP2 (since R20.028 to be precise).
The issue is that the Xpresso tag is executed from the user interaction and the thread responsible to update the data. Since user interaction are done in the main thread a correct workaround is to do checks for it like soimport c4d def main(): node = op nodeMaster = node.GetNodeMaster() owner = nodeMaster.GetOwner() hostObject = owner.GetObject() if Input1 == 1 and c4d.threading.GeIsMainThread(): if hostObject[c4d.ID_USERDATA,2] == 0: hostObject[c4d.ID_USERDATA,2] = 1 else: hostObject[c4d.ID_USERDATA,2] = 0
Finnally note this is not an issue related to Python but a more general issue regarding Xpresso.
In any case, I've open a bug report.Cheers,
Maxime. -
Hi @m_adam
Thanks for the response especially the specific version it changed.
Since I'm expecting the file will be used by versions below R20,
I just added this line in the code:if c4d.GetC4DVersion() >= 20028 : if Input1 == 1 and c4d.threading.GeIsMainThread(): # Do Something else: if Input1 == 1: # Do Something
Thanks again. Have a great day ahead!
-
My workaround still works for earlier version so you don't really need to check for version but it's up to you.
Cheers,
Maxime.