最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

trace32 - python API wait for .cmm script to finish (Practice stack depth error) - Stack Overflow

programmeradmin2浏览0评论

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
  • How did you verify instance.cmm("testScript.cmm") is not blocking until testScript.cmm finished? – dev15 Commented Mar 20 at 13:27
Add a comment  | 

1 Answer 1

Reset to default 0

After debugging in the Lauterbach python library I know how the .cmm() function is working:

  1. The function gets the current stack dept.
  2. It fires the script execution command.
  3. 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 :)

发布评论

评论列表(0)

  1. 暂无评论