sleep

Upper limit in Python time.sleep()?

旧街凉风 提交于 2019-11-29 15:51:59
Is there an upper limit to how long you can specify a thread to sleep with time.sleep()? I have been having issues with sleeping my script for long periods (i.e., over 1k seconds). This issue has appeared on both Windows and Unix platforms. I suppose the longer the time the more probable situation described in the docs : The actual suspension time may be less than that requested because any caught signal will terminate the sleep() following execution of that signal’s catching routine. Also, the suspension time may be longer than requested by an arbitrary amount because of the scheduling of

How do I wake up a sleeping pthread?

妖精的绣舞 提交于 2019-11-29 15:01:45
问题 I'm writing a program in C++. I've noticed that it's gaining a number of threads whose purpose is to do something at intervals, there are 3 or 4 of them. I decided to refactor by writing a scheduler service that the other places that use these threads could subscribe to, which should reduce the number of extra event threads I have running at any time to just one. I don't have any code that uses this yet; before I start writing it I'd like to know if it's possible, and get some feedback on my

Sleep for exact time in python

倾然丶 夕夏残阳落幕 提交于 2019-11-29 14:16:50
I need to wait for about 25ms in one of my functions. Sometimes this function is called when the processor is occupied with other things and other times it has the processor all to itself. I've tried time.sleep(.25) but sometimes its actually 25ms and other times it takes much longer. Is there a way to sleep for an exact amount of time regardless of processor availability? Because you're working with a preemptive operating system, there's no way you can guarantee that your process will be able to have control of the CPU in 25ms. If you'd still like to try, it would be better to have a busy

SystemClock.sleep() vs. Thread.sleep() while waiting for a semaphore loop

こ雲淡風輕ζ 提交于 2019-11-29 14:16:21
问题 In order to synchronize/queue access to a shared resource, I am about to use a Semaphore, aided by a wait loop. In order not to run into CPU pegging, I would like to sleep() a little bit inside that while loop. I searched the http://developer.android.com reference and found two such sleep() functions and I am confused as to which one fits which scenario: Thread.sleep() SystemClock.sleep() Which one better suits the case I described and why? 回答1: First of all, do you really need a wait loop?

Delay execution 1 second

二次信任 提交于 2019-11-29 14:09:34
So I am trying to program a simple tick-based game. I write in C++ on a linux machine. The code below illustrates what I'm trying to accomplish. for (unsigned int i = 0; i < 40; ++i) { functioncall(); sleep(1000); // wait 1 second for the next function call } Well, this doesn't work. It seems that it sleeps for 40 seconds, then prints out whatever the result is from the function call. I also tried creating a new function called delay, and it looked like this: void delay(int seconds) { time_t start, current; time(&start); do { time(&current); } while ((current - start) < seconds); } Same result

sleep() delays output until end [duplicate]

旧巷老猫 提交于 2019-11-29 14:02:45
Possible Duplicate: Why does printf not flush after the call unless a newline is in the format string? (in C) I'm using the sleep() function in C, and am running into a problem: I wasn't sure that this was the problem so I boiled the entire code down to this: int main() { printf("1"); sleep(3); printf("2"); return 0; } What I thought this should produce is 1 .. wait for 3 seconds .. 2. Instead the program waits for 3 seconds and then prints 12. Is there any way to use the sleep function so that I get the first output? Thanks It's not actually the sleep function which is delaying the output, it

Using Thread.Sleep in Xamarin.Forms

戏子无情 提交于 2019-11-29 12:11:14
问题 I want to execute the following MainPage = new ContentPage { Content = new StackLayout { Children = { new Button { Text = "Thread.Sleep", Command = new Command(() => { Thread.Sleep(1000); MainPage.Animate("", x => MainPage.BackgroundColor = Color.FromRgb(x, x, x)); }), }, new Button { Text = "Task.Run + Thread.Sleep", Command = new Command(async () => { await Task.Run(() => Thread.Sleep(1000)); MainPage.Animate("", x => MainPage.BackgroundColor = Color.FromRgb(x, x, x)); }) }, new Button {

WHY does Thread.sleep() clear the interrupted flag?

本秂侑毒 提交于 2019-11-29 11:50:12
I know that some Thread methods clear the interrupted flag (e.g. sleep, wait, ...). But why do they do this? What is the reason for it? That is a result of interruption being designed not to be totally synonymous with cancellation. The guidance from Oracle is to use interruption only for cancellation, but that view may have been arrived at over time. In any event the design doesn't force that. You can design a task to respond to interruption, then go back to what it was doing. In Java Concurrency in Practice, 7.1, page 138, it says: There is nothing in the API or language specification that

Sleep is not working on pyqt4

自作多情 提交于 2019-11-29 11:45:58
I have got this problem. I´m trying to set text on a lineEdit object on pyqt4, then wait for a few seconds and changing the text of the same lineEdit. For this I´m using the time.sleep() function given on the python Time module. But my problem is that instead of setting the text, then waiting and finally rewrite the text on the lineEdit, it just waits the time it´s supposed to sleep and only shows the final text. My code is as follows: from PyQt4 import QtGui from gui import * class Ventana(QtGui.QMainWindow, Ui_MainWindow): def __init__(self, parent=None): QtGui.QWidget.__init__(self, parent)

Do sleep functions sleep all threads or just the one who call it?

大城市里の小女人 提交于 2019-11-29 10:22:32
I am programming with pthread on linux(Centos)? I wanna to threads sleep a short time to wait for something. I am trying to use sleep(), nanosleep(), or usleep() or maybe something can do that. I want to ask that: Do sleep functions sleep all threads or just the one who call it? Any advices or references would be appreciate. void *start_routine () { /* I just call sleep functions here */ sleep (1); /* sleep all threads or just the one who call it? what about nanosleep(), usleep(), actually I want the threads who call sleep function can sleep with micro-seconds or mili-seconds. */ ... } int