How can python await delay_sim and delay_app? #371
Replies: 1 comment 2 replies
-
To use delays in python they python code must be running as part of a MAST/PyMAST label. Meaning it is code scheduled and running in the MAST runtime. The examples mentioned in npc cag are scheduled labels. They are decorated with the @Label, they are schedule to run in the MAST runtime. task_schedule(self.tick_fighter_launch)
task_schedule(self.tick_fighter_manage) The correct way is to yield and AWAIT that wraps the delay yield AWAIT(delay_sim(seconds=10)) Low Level details A PyMAST label is a python function. More importantly it is a generator function. These functions run until they yield or end. This is NOT the same as the normal python execution of a function. This is at a low level similar to the python "async" functions. Python "async" cannot be used because the cosmos system does not support multithreading or long running functions. PyMAST python labels can jump to other labels as well. They run like MAST labels using a different runtime ticker. Much is done leveraging generator functions that progress then yield for a given slice of execution. The Pythons script code in cosmos must NEVER block the main execution. MAST and PyMAST allow the script to 'pause' and pickup later in a non-blocking manner. So a Delay functions actual yields execution until the specified time is reached and then continues on. The engine runs, calls the script, it yields, and this repeats until the delay time is reached. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I want to
await delay_sim(duration)
from python. How is this possible, or is it not?Some ways I've tried and failed:
npc_cag.py has a couple uses of AWAIT(delay_sim(...)), like this
But when I try it, no delay happens; the function executes as if the AWAIT line was not there.
(Note that the yield keyword in python is not the same as the yield keyword in mast.)
Beta Was this translation helpful? Give feedback.
All reactions