sleep

Testing with Thread.sleep

烂漫一生 提交于 2019-12-01 04:13:08
What are the recommended approaches to using Thread.sleep() to speed up tests. I am testing a network library with a retry functionality when connections are dropped or timeout errors occur, etc. The library however, uses a Thread.sleep() between the retries (so it won't connect thousands times while the server is restarting). The call is slowing the unit tests significantly, and I wonder what the options are to override it. Note, I'm open to actually changing the code, or using a mocking framework to mock Thread.sleep(), but would like to hear your opinions/recommendation first. It is usually

Python time.sleep vs busy wait accuracy

ⅰ亾dé卋堺 提交于 2019-12-01 03:52:41
I was playing around with the time.sleep function from python's standard library and found it inadequate for sub-ms delays. From testing I found it to actually wait 1.1-1.2 ms for a 1ms wait. Implementing a busy wait got the accuracy to within 1%. I used: def busy_wait(dt): current_time = time.time() while (time.time() < current_time+dt): pass and could get down to 0.0001 seconds before breaking 1% accuracy. The main questions I have are: Why is the sleep function so inaccurate (possibly a C issue)? Will getting a better CPU with a higher clock speed change this? Why would anyone use sleep?

What is the effect of changing system time on sleeping threads?

梦想的初衷 提交于 2019-12-01 02:56:55
问题 If you take a look at the clock_gettime() function, which is available in all BSDs and is actually defined as part of the POSIX standard, you see that there is support for at least three types of clocks (many systems support more than these clocks, but actually the POSIX standard only demands one to be present, all others are optional): CLOCK_REALTIME - POSIX demands this to be present. This is the wall time clock. CLOCK_MONOTONIC - No idea what this is (and what SI seconds mean), but I

Difference among sleep() and usleep() in PHP

与世无争的帅哥 提交于 2019-12-01 02:14:20
Can any body explain me what is the difference among sleep() and usleep() in PHP. I have directed to use following scripts to do chat application for long pulling but in this script I am getting same effect using usleep(25000); or without usleep(25000); page1.php <script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js" type="text/javascript"></script> <script> var lpOnComplete = function(response) { console.log(response); // do more processing lpStart(); }; var lpStart = function() { $.post('page2.php', {}, lpOnComplete, 'json'); }; $(document).ready(lpStart); </script> page2

Testing with Thread.sleep

…衆ロ難τιáo~ 提交于 2019-12-01 01:03:34
问题 What are the recommended approaches to using Thread.sleep() to speed up tests. I am testing a network library with a retry functionality when connections are dropped or timeout errors occur, etc. The library however, uses a Thread.sleep() between the retries (so it won't connect thousands times while the server is restarting). The call is slowing the unit tests significantly, and I wonder what the options are to override it. Note, I'm open to actually changing the code, or using a mocking

Update UI with Thread sleep

夙愿已清 提交于 2019-12-01 00:46:04
I'm busy with making an app for an android device. And now I'm testing with some things. I want to change the background color limited times, lets say 5. Every time the background's changed, I want it to change again after 2-3 seconds. If I am using the Thread class, it loads the whole template after the Thread has finished, you can't see the color changes, but they're running in the "background" (I can see that in LogCat). I hope that there is a tutorial or an example that I can use. Thanks! I recently learned how to do this. There is a good tutorial here: http://www.vogella.com/articles

How to make a thread sleep/block for nanoseconds (or at least milliseconds)?

↘锁芯ラ 提交于 2019-11-30 23:13:23
问题 How can I block my thread (maybe process) for nanoseconds or maybe for a milliseconds (at least) period? Please note that I can't use sleep, because the argument to sleep is always in seconds. 回答1: nanosleep or clock_nanosleep is the function you should be using (the latter allows you to specify absolute time rather than relative time, and use the monotonic clock or other clocks rather than just the realtime clock, which might run backwards if an operator resets it). Be aware however that you

Difference among sleep() and usleep() in PHP

柔情痞子 提交于 2019-11-30 21:43:52
问题 Can any body explain me what is the difference among sleep() and usleep() in PHP. I have directed to use following scripts to do chat application for long pulling but in this script I am getting same effect using usleep(25000); or without usleep(25000); page1.php <script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js" type="text/javascript"></script> <script> var lpOnComplete = function(response) { console.log(response); // do more processing lpStart(); }; var lpStart =

Iphone app is delayed for 10 -15 minutes when iphone is in sleep mode

荒凉一梦 提交于 2019-11-30 21:18:43
问题 I have created an app that uses NSTimer, which gets triggered each second. My problem is that if the Iphone is in sleep mode i get a delay for 10 to 15 minutes before the event is triggered. I have stackoverflowed and googled this and the reason for this seems to be that the phone stops listening for certain events when in sleep mode. Some people have solved this issue by playing a mute sound, not allowing the phone to sleep. What could be the reason for the delay? The mute sound solution

Adding a delay without Thread.sleep and a while loop doing nothing

纵饮孤独 提交于 2019-11-30 21:14:36
I need to add delay without using Thread.sleep() or a while loop doing nothing. The game im editing(Minecraft) clock runs on "Ticks" but they can fluctuate depending on your FPS. public void onTick() {//Called every "Tick" if(variable){ //If my variable is true boolean = true; //Setting my boolean to true /** *Doing a bunch of things. **/ //I need a delay for about one second here. boolean = false; //Setting my boolean to false; } } The reason why i need a delay is because if i dont have one the code runs too fast and misses it and does not toggle. Something like the following should give you