Ask a Question

Difference between Delay() and time.sleep() (python)

SOLVED
MartinMet
New Contributor

Difference between Delay() and time.sleep() (python)

Does someone know the qualitative difference between TestCompletes innate 'Delay()' and time.sleep() in Python? I currently have a listener to a connection to ActiveMQ via stomp, and whenever a message arrives the listener will open a file and write the message to this file. Whenever I ran the code nothing was written in the file and when I tried deleting it I got an error stating that TC was still using this file. After some debugging I switched out TC:s innate Delay() to time.sleep() and then everything suddenly works.

2 ACCEPTED SOLUTIONS

Accepted Solutions
abishekhari007
Contributor

Re: Difference between Delay() and time.sleep() (python)

Use the aqUtils. Delay method to delay the script execution for a period of time. You may want to delay the script execution when the application under test is performing some time-consuming operations (for example, when it is loading a database or connecting to a network computer).

The sleep() function suspends (waits) execution of the current thread for a given number of seconds.

 

https://support.smartbear.com/testcomplete/docs/reference/program-objects/aqutils/delay.html#:~:text...

 

https://support.smartbear.com/testcomplete/docs/app-objects/common-tasks/waiting-process-or-window-a...

View solution in original post

AlexKaras
Community Hero

Re: Difference between Delay() and time.sleep() (python)

Hi,

 

I currently have a listener to a connection to ActiveMQ via stomp

Are the listener and other test code exist in the same TestComplete's project and are executed concurrently?

If yes, then note that multithreaded test code is not officially supported by TestComplete. It might work for certain script engines (like Python) but nothing is guaranteed.

Instead, I would implement a listener in a separate script and execute it in the standalone Python instance (probably, started from TestComplete when needed and terminated when done) and in TestComplete itself leave only the part that checks the content of the file.

 

Regards,
  /Alex [Community Hero]
____
[Community Heroes] are not employed by SmartBear Software but
are just volunteers who have some experience with the tools by SmartBear Software
and a desire to help others. Posts made by [Community Heroes]
may differ from the official policies of SmartBear Software and should be treated
as the own private opinion of their authors and under no circumstances as an
official answer from SmartBear Software.
The [Community Hero] signature is used with permission by SmartBear Software.
https://community.smartbear.com/t5/custom/page/page-id/hall-of-fame
================================

View solution in original post

5 REPLIES 5
abishekhari007
Contributor

Re: Difference between Delay() and time.sleep() (python)

Use the aqUtils. Delay method to delay the script execution for a period of time. You may want to delay the script execution when the application under test is performing some time-consuming operations (for example, when it is loading a database or connecting to a network computer).

The sleep() function suspends (waits) execution of the current thread for a given number of seconds.

 

https://support.smartbear.com/testcomplete/docs/reference/program-objects/aqutils/delay.html#:~:text...

 

https://support.smartbear.com/testcomplete/docs/app-objects/common-tasks/waiting-process-or-window-a...

View solution in original post

MartinMet
New Contributor

Re: Difference between Delay() and time.sleep() (python)

@abishekhari007 Why would the aqUtils.Delay() cause a deadlock in writing to the file whereas time.sleep() does not then? Is it because the writing is supposed to happen during the delay and aqUtils.Delay() just pauses the entire script execution, including the interrupting class, whereas time.sleep() allows for it to run?

AlexKaras
Community Hero

Re: Difference between Delay() and time.sleep() (python)

Hi,

 

I currently have a listener to a connection to ActiveMQ via stomp

Are the listener and other test code exist in the same TestComplete's project and are executed concurrently?

If yes, then note that multithreaded test code is not officially supported by TestComplete. It might work for certain script engines (like Python) but nothing is guaranteed.

Instead, I would implement a listener in a separate script and execute it in the standalone Python instance (probably, started from TestComplete when needed and terminated when done) and in TestComplete itself leave only the part that checks the content of the file.

 

Regards,
  /Alex [Community Hero]
____
[Community Heroes] are not employed by SmartBear Software but
are just volunteers who have some experience with the tools by SmartBear Software
and a desire to help others. Posts made by [Community Heroes]
may differ from the official policies of SmartBear Software and should be treated
as the own private opinion of their authors and under no circumstances as an
official answer from SmartBear Software.
The [Community Hero] signature is used with permission by SmartBear Software.
https://community.smartbear.com/t5/custom/page/page-id/hall-of-fame
================================

View solution in original post

MartinMet
New Contributor

Re: Difference between Delay() and time.sleep() (python)

Ah okay thank you, that makes sense. The listener and the test code are both in the same script, and I guess that Python somehow allowed for multi-threading using the wait() operation. Thanks for the suggestion!

alexaminar
Visitor

Re: Difference between Delay() and time.sleep() (python)

Python sleep() will pause for an hour, day or whatever if given the proper value. It does not allow other processes take place (in same script) however. A better way is to use an event which will create an event on timeout.

 

cancel
Showing results for 
Search instead for 
Did you mean: