Ask a Question

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

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.


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.

@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?

Community Hero



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.


  /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.

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!

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.


Showing results for 
Search instead for 
Did you mean: