Python time module implemented?

I was trying to figure out if the python time module was implemented in 088 but it seems that it isn’t. I would have liked to use the sleep method:

import time time.sleep(3) print(a) time.sleep(3) print(b)

Does not seem to work.

time is working, in both textport and via a script. it pauses TouchDesigner, which is what the tscript command does as well. what part is not working for you?

import time print(time.clock()) time.sleep(3) print(time.clock())

output

6.003840656868199e-07 2.9994263330252364

After retesting, i see now that it outputs the print to the textport, but the two prints come together at the same time after the sleep, and not first the first print, then a pause, then the second print.

That would be expected since the script is still executing, which doesn’t give TD a chance to redraw and show results.

wow, many thanks for the explanation, Malcom, it’s clearer now.

So, if I correctly understood, every script inside TD is running into the “GUI” thread. Thus, nothing is separated from the user interface (network builder), and it’s why when one runs scripts that are long to process, TD freezes until the script finishes and the GUI is updated…

I thought i would have expected the python virtual machine to run into its own thread, but apparently it is not. Therefore, there are no “asynchronous” processes inside TD.

It has been a subject of interrogation to me whether scripts could run into their own pace while the user interface had its own, different, process.

Ok, going back to sleep, by now. :sunglasses:

The key thing is that the scripts almost always need to interface with the network (fetching nodes, getting their values, modifying them etc.) so they can’t be asynchronous to them.

What makes me ponder is that if I split actions into separate scripts, the phenomen is the same, and furthermore, the timing is not respected.

Example:

text1:

import time
time.sleep(3)
print("action 1")
op('text2').run()

text2:

import time
time.sleep(3)
print("action 2")
op('text3').run()

text3:

import time
time.sleep(3)
print("action 3")

Will output, at the same time, and after 9 seconds:

python >>> 
action 2
action 3
action 1

It is not what would be expected.

That makes sense if all 3 scripts execute on the same frame, so the frame ends up taking 9 seconds to execute.

This is where one didn’t know, as a user, if scripts are executed at the frame level only.

There are many things going on during one and only frame inside the network editor, as the sequence of cooking inside a network is operating at the subframe level.

So, there is to my sense a difficulty in scripting networks.

For example implementing a loop often doesn’t make sense at the script (frame) level, but only at the network level. So scripts are sometimes too much high-level abstraction, and one has to build one’s own loop (incrementation system) with different node operators and not within one single script.

Can you give an example of such a case to help us further understand your needs?

I was just thinking aloud, no real needs here. Sometimes I planned to write “big” scripts thinking it will make things more concise and quicker, but I found out that in many cases, in my usage, little tiny scripts disseminated here and there within the networks may be in fact far more flexible than long monolithic ones. Thanks.