sleep

PHP: sleep() for particular line of code

旧时模样 提交于 2019-12-05 11:38:12
is it possible to use sleep() (or some other function) to wait before execution? I have for example: <div>bla bla</div> <?php $a echo $a; ?> some divs and html <?php $b echo $b; ?> How to execute the first php script say 5 sec after the page has loaded but to show everything else as the page loads? If I use sleep() before the first php it will delay the whole page from loading. You want to use AJAX for this. Example using jQuery: <div id="content"> <-- You want to load something here after 5 seconds --> </div> <script type="text/javascript"> setTimeout(function() { $('#content').load("/url/to

Typing effect in Python

可紊 提交于 2019-12-05 11:08:13
I want to make such program which reads characters from a string and prints each character after some delay so its look like typing effect. Now my problem is sleep function is not working properly. It print whole sentence after long delay. import sys from time import sleep words = "This is just a test :P" for char in words: sleep(0.5) sys.stdout.write(char) I use "sys.stdout.write" for removing whitespace between characters. you should use sys.stdout.flush() after each iteration The problem is that stdout is flushed with the newline or manually with sys.stdout.flush() So the result is import

Python sleep without interfering with script?

情到浓时终转凉″ 提交于 2019-12-05 10:14:03
Hey I need to know how to sleep in Python without interfering with the current script. I've tried using time.sleep() but it makes the entire script sleep. Like for example import time def func1(): func2() print("Do stuff here") def func2(): time.sleep(10) print("Do more stuff here") func1() I want it to immediately print Do stuff here, then wait 10 seconds and print Do more stuff here. Interpreting your description literally, you need to put the print statement before the call to func2() . However, I'm guessing what you really want is for func2() to a background task that allows func1() to

Sleep() in Android Java

六眼飞鱼酱① 提交于 2019-12-05 09:54:07
问题 I am following this tutorial to have a loading screen in my program. The tutorial says my activity should Sleep() using the Sleep() command, however it does not recognize Sleep() as a function and provides me with an error, asking if I would like to create a method called Sleep(). Here is the code sample: public class LoadingScreenActivity extends Activity { //Introduce an delay private final int WAIT_TIME = 2500; @Override protected void onCreate(Bundle savedInstanceState) { // TODO Auto

Why does Sleep() slow down subsequent code for 40ms?

ε祈祈猫儿з 提交于 2019-12-05 08:34:05
I originally asked about this at coderanch.com, so if you've tried to assist me there, thanks, and don't feel obliged to repeat the effort. coderanch.com is mostly a Java community, though, and this appears (after some research) to really be a Windows question, so my colleagues there and I thought this might be a more appropriate place to look for help. I have written a short program that either spins on the Windows performance counter until 33ms have passed, or else calls Sleep(33). The former exhibits no unexpected effects, but the latter appears to (inconsistently) slow subsequent

Network access when the Android phone is asleep

拟墨画扇 提交于 2019-12-05 08:17:40
I'm using a combination of alarm (set with AlarmManager ) and background service to periodically synchronize data in my application. The only problem I have is that when sleep policy terminates Wi-Fi connection the synchronization no longer works. Is there a way to "wake up" the Wi-Fi connection that has been put to sleep? GMail somehow manages to do that because it notifies me about new e-mail even if the phone entered sleep mode. [update]You can use a WifiLock to keep WiFi active, while holding the lock. Using an AlarmManager and a Service says to me your service is running only for a very

What does “2>&1” in a Windows Command Do?

孤街浪徒 提交于 2019-12-05 07:26:44
Doing some maintenance on a script, I found this line: ping -n 40 127.0.0.1 > NUL 2>&1 I know from this question that everything up to the NUL causes the script to sleep for 39 seconds. But I don't know what the rest of the command does. What does the 2>&1 do? Decomposing the line ping -n 40 127.0.0.1 Send 40 ping packets to local host. If there is not any problem the default behaviour is to wait 1 second between packets, so it generates a 39 second delay >nul or 1>nul Redirects anything written to the standard output stream (stream number 1) to the nul device. Anything sent to this device is

When does Thread.sleep(1000) sleeps less than 1000 milliseconds?

孤街醉人 提交于 2019-12-05 07:00:25
In this interesting article about falsehoods programmers believe about time , one of them is Thread.sleep(1000) sleeps for >= 1000 milliseconds. When isn't this true? According to this (Implementation of the sleep by windows operating system, which is what Thread.sleep will call underneath): If dwMilliseconds is less than the resolution of the system clock, the thread may sleep for less than the specified length of time. If dwMilliseconds is greater than one tick but less than two, the wait can be anywhere between one and two ticks, and so on. To increase the accuracy of the sleep interval,

What else can i do 'sleep' when the sleep() can't work well with alarm?

ぐ巨炮叔叔 提交于 2019-12-05 06:31:29
There are many documents say "you should avoid using sleep with alarm, since many systems use alarm for the sleep implementation". And actually, I'm suffering with this problem. So does anyone can help me that what else i can do 'sleep' when the sleep() can't work well with alarm? I have already tried 'usleep' of the Time::HiRes module, and select() function. But they didn't work either. You can try AnyEvent : use AnyEvent; my $cv = AnyEvent->condvar; my $wait_one_and_a_half_seconds = AnyEvent->timer( after => 1.5, cb => sub { $cv->send } ); # now wait till our time has come $cv->recv; DrHyde

How can I guarantee that Thread.sleep sleeps for at least that amount of time?

落花浮王杯 提交于 2019-12-05 06:03:15
As per this question , Thread.sleep is not necessarily guaranteed to sleep for the duration you specify: it may be shorter or longer. If you read the documentation for Thread.sleep , you'll see there are no strong guarantees over the exact duration which will be slept. It specifically states the duration is subject to the precision and accuracy of system timers and schedulers which is (intentionally) vague but hints that the duration should not be relied upon too heavily. The granularity of possible sleep durations on a particular operating system is determined by the thread scheduler's