I am using python with the lauterbach.trace32.rcl library to control a trace32 instance. I am getting sporadic 'Practice stack depth error' while calling multiple cmm files My goal is to call a .cmm script and wait for the script to complete before calling another one.
My current python script looks like this (simplified):
instance.cmm("testScript.cmm")
instance.cmd("SYStem.Mode Go")
This causes problems because the second command is being executed while the testScript.cmm
is still running.
I noticed that putting a simple time.sleep(1)
between the two lines would resolve the issue, but I don't like the solution because in some cases the script may need more time to complete the execution:
instance.cmm("testScript.cmm")
time.sleep(1) # wait for 1 second
instance.cmd("SYStem.Mode Go")
Is there a more intelligent solution?
Thank you for helping out <3
UPDATE:
I found out that the parameter timeout=None
should do the trick, but still this does not work for me... :(
instance.cmm("testScript.cmm", timeout=None)
I am using python with the lauterbach.trace32.rcl library to control a trace32 instance. I am getting sporadic 'Practice stack depth error' while calling multiple cmm files My goal is to call a .cmm script and wait for the script to complete before calling another one.
My current python script looks like this (simplified):
instance.cmm("testScript.cmm")
instance.cmd("SYStem.Mode Go")
This causes problems because the second command is being executed while the testScript.cmm
is still running.
I noticed that putting a simple time.sleep(1)
between the two lines would resolve the issue, but I don't like the solution because in some cases the script may need more time to complete the execution:
instance.cmm("testScript.cmm")
time.sleep(1) # wait for 1 second
instance.cmd("SYStem.Mode Go")
Is there a more intelligent solution?
Thank you for helping out <3
UPDATE:
I found out that the parameter timeout=None
should do the trick, but still this does not work for me... :(
instance.cmm("testScript.cmm", timeout=None)
Share
Improve this question
edited Mar 25 at 10:00
BeanBoy
asked Mar 19 at 8:42
BeanBoyBeanBoy
9058 silver badges14 bronze badges
1
|
1 Answer
Reset to default 0After debugging in the Lauterbach python library I know how the .cmm() function is working:
- The function gets the current stack dept.
- It fires the script execution command.
- The function stays in a loop until the stack depth is the same as before. If the timeout is reached it raises an error (TimeoutError). If the stack depth is less than it was before it raises an error (PracticeError: Practice stack depth error).
So the function ONLY uses the stack depth to know if the cmm script is complete. Very interesting...
My problem was not as I expected that the cmm function returned before the cmm script was complete, instead the problem is that the function starts the script while whatever process is still running in the instance.
To prevent the 'Practice stack depth error' I created a wrapper function in my python script which waits until the stack depth is 0 and then starts the cmm call:
@staticmethod
def call_synchronous_cmm(instance, cmm_file: str, timeout_s=60):
start_time: float = time.time()
# wait for the trace stack depth to be 0
while instance.fnc('PRACTICE.SD()') != 0:
if time.time() - start_time > timeout_s:
raise TimeoutError(f'Timeout: Stack depth is not 0 after {timeout_s}s')
time.sleep(.1)
# now the stack depth is 0, we can call the cmm file
instance.cmm(cmm_file, timeout=timeout_s)
This is the (for me) working solution.
I can sleep in peace again :)
instance.cmm("testScript.cmm")
is not blocking untiltestScript.cmm
finished? – dev15 Commented Mar 20 at 13:27