sleep

Accurate sleep/delay within Python while loop

早过忘川 提交于 2019-12-04 06:19:41
问题 I have a while True loop which sends variables to an external function, and then uses the returned values. This send/receive process has a user-configurable frequency, which is saved and read from an external .ini configuration file. I've tried time.sleep(1 / Frequency), but am not satisfied with the accuracy, given the number of threads being used elsewhere. E.g. a frequency of 60Hz (period of 0.0166667) is giving an 'actual' time.sleep() period of ~0.0311. My preference would be to use an

Gradle - How to add some delay pause hang in Gradle

泪湿孤枕 提交于 2019-12-04 06:17:20
Im looking for a way to insert a pause of few seconds between the calls of two gradle tasks. I can use firstTask.doLast { ..... } something like which can do Linux/Unix sleep 45 Any ideas? First, I'd try to find a better solution than waiting for so long every time. Anyway, to delay the first task for 45 seconds, you can do: firstTask.doLast { sleep(45 * 1000) } A good way to familiarize yourself with Groovy's core APIs is to study the Groovy JDK (also known as GDK). It's also a handy reference. If you want to run integration tests in Tomcat, then simply use the Gradle Tomcat Plugin like this:

Bash date/time arithmetic

我与影子孤独终老i 提交于 2019-12-04 05:27:38
I have a little Bash script which suspends the computer after a given number of minutes. However, I'd like to extend it to tell me what the time will be when it will be suspended, so I can get a rough idea of how long time I have left so to speak. #!/bin/sh let SECS=$1*60 echo "Sleeping for" $1 "minutes, which is" $SECS "seconds." sleep $SECS && pm-suspend The only argument to the script will be how many minutes from now the computer should be suspended. All I want to add to this script is basically an echo saying e.g. "Sleeping until HH:nn:ss!". Any ideas? Found out how. echo "The computer

C# Sleep for 500 milliseconds

懵懂的女人 提交于 2019-12-04 05:11:37
Could you please tell me how do I go about pausing my program for 500 milliseconds and then continue? I read Thread.Sleep(500) is not good as it holds up the GUI thread. Using a timer it fires a callback ... I just want to wait 500ms and then continue to the next statement. Please advise. EDIT: I need to display a status bar message for 500ms and then update the message with a different one. Sorry, I meant 500 not 50. EDIT: I do understand what all you have said. but: [I just want to wait 500ms and then continue to the next statement.] I think because it is such a short interval i am going do

C sleep function not working

纵然是瞬间 提交于 2019-12-04 05:02:19
When including the sleep function from unistd.h the program hangs indefinitely: #include <stdio.h> #include <unistd.h> int main() { int i; printf("0 "); for(i = 1; i <20; ++i) { sleep(2); printf("%d ", i); } printf("\n"); return 0; } The rest runs fine when sleep(2) is commented out, any ideas? There's nothing wrong with the code, but note that in many cases the output of printf is buffered, meaning that the output appears on the console only if you explicitly call fflush(stdout) , you print a newline, or the buffer becomes full. Since you don't print a newline until the very end, you will see

How accurate is Sleep() or sleep()

杀马特。学长 韩版系。学妹 提交于 2019-12-04 04:26:26
问题 I'm trying simulate a key down and key up action. For example: 2638 millseconds. SendMessage(hWnd, WM_KEYDOWN, keyCode, 0); Sleep(2638); SendMessage(hWnd, WM_KEYUP, keyCode, 0); How would you know if it really worked? 回答1: You wouldn't with this code, since accurately measuring the time that code takes to execute is a difficult task. To get to the question posed by your question title (you should really ask one question at a time...) the accuracy of said functions is dictated by the operating

In there something similar to Java's Thread.yield() in Python? Does that even make sense?

北战南征 提交于 2019-12-04 03:38:32
I want to tell my Python threads to yield, and so avoid hogging the CPU unnecessarily. In Java, you could do that using the Thread.yield() function. I don't think there is something similar in Python, so I have been using time.sleep(t) where t = 0.00001 . For t=0 there seems to be no effect. I think that maybe there is something I am not understanding correctly about Python's threading model, and hence the reason for the missing thread.yield() . Can someone clarify this to me? Thanks! PS: This is what the documentation for Java's Thread.yield() says: Causes the currently executing thread

Does Capybara require sleep to work?

大城市里の小女人 提交于 2019-12-04 03:22:45
Apparently, sleep or wait_until are not valid using recent versions of Capybara, according to the webpage updates . However, I have a set of tests that only work on fast machines if I add a sleep(1) call to the test. That is, a test that looks like: describe "dosimeters page" do before do click_link("Dosimeter Read History", :match=>:first) end ... becomes describe "dosimeters page" do before do unix_wait click_link("Dosimeter Read History", :match=>:first) end ... where I've defined unix_wait as: def unix_wait case RbConfig::CONFIG['host_os'] when /darwin/ when /linux-gnu/ sleep(1) end end

Qt detect when computer goes into sleep?

岁酱吖の 提交于 2019-12-04 03:06:05
问题 How can i detect when a users computer goes into sleep (laptop lid closes, sleep mode due to inactivity, etc)? I need to do this to disconnect the users TCP connection. Basically we got a simple chat application where we want to take the user off-line. 回答1: There is no Qt way to detect when computer goes to sleep or hibernation. But there are some platform dependent ways to do it. On Windows you can listen for the WM_POWERBROADCAST message in your WindowProc handler: LRESULT WndProc(HWND hWnd

Are longer sleeps (in C++) less precise than short ones

China☆狼群 提交于 2019-12-04 02:47:02
问题 I have a task to do something every "round" minute(at xx:xx:00) And I use something like const int statisticsInterval=60; time_t t=0; while (1) { if (abs(t-time(NULL)==0)) //to avoid multiple calls in the same second that is the multiple of 60 boost::this_thread::sleep(boost::posix_time::seconds(2));//2, not 1 to make sure that 1 second passes t=time(NULL); boost::this_thread::sleep(boost::posix_time::seconds(statisticsInterval-(t%statisticsInterval))); //DO WORK } As you can see I use sleep