sleep

Program freezes during Thread.sleep() and with Timer

混江龙づ霸主 提交于 2019-12-17 02:26:29
问题 Original question: This method is supposed to change the image being displayed on a JFrame gradually into another image. However, without some way to slow it down, it just seems to change from one image to the new image. In order to slow it down, I put in a Thread.sleep(1000) so the changes wouldn't happen instantly. However, with this line in there, my program freezes completely. No error message, no nothing. Can anyone please help me out? Suggest a better method to slow it down, or how this

How do I make a delay in Java?

僤鯓⒐⒋嵵緔 提交于 2019-12-16 20:13:10
问题 I am trying to do something in Java and I need something to wait / delay for an amount of seconds in a while loop. while (true) { if (i == 3) { i = 0; } ceva[i].setSelected(true); // I need to wait here ceva[i].setSelected(false); // I need to wait here i++; } I want to build a step sequencer and I'm new to Java. Any suggestions? 回答1: If you want to pause then use java.util.concurrent.TimeUnit : TimeUnit.SECONDS.sleep(1); To sleep for one second or TimeUnit.MINUTES.sleep(1); To sleep for a

how can I pause and then resume a call to `sleep`

僤鯓⒐⒋嵵緔 提交于 2019-12-14 03:45:34
问题 Calling sleep(10) means to sleep for the specified number of seconds. When I type "sleep 10" I suppose to wait 10 seconds but when I'm using CTRL-Z (or sending SIGTSTP ) right after sleep command, it won't stop the "timer" (or the counter) even though that the process has stopped. I can see via jobs that the status of sleep has changed to STOPPED but if I'll wait 10 seconds and then send this process to the foreground it will finish immediately , even though it run less then 10 seconds. So,

How to set AutoHotKey process priority & radom sleep?

大兔子大兔子 提交于 2019-12-14 03:03:01
问题 I want to set the high priority on the script below (only first). Another important thing is whether you can do a Radom Sleep, 250 to 350 ?? Loop { { ImageSearch,,, 0, 0, A_ScreenWidth, A_ScreenHeight, mor.png bT:= ErrorLevel ? bT : 1 If bT { bT:= 0 Random, x, 1130, 1300 Random, y, 580, 680 Click % x % % y % Sleep, 500 } } ImageSearch,,, 0, 0, A_ScreenWidth, A_ScreenHeight, biz.png bT:= ErrorLevel ? bT : 1 { bT:= 0 Random, x, 540, 618 Random, y, 419, 430 Click % x % % y % } } Return f1::

pthread sleep function, cpu consumption

人盡茶涼 提交于 2019-12-13 18:58:31
问题 On behalf, sorry for my far from perfect English. I've recently wrote my self a demon for Linux (to be exact OpenWRT router) in C++ and i came to problem. Well there are few threads there, one for each opened TCP connection, main thread waiting for new TCP connections and, as I call it, commander thread to check for status. Every thing works fine, but my CPU is always at 100%. I now that its because of the commander code: void *CommanderThread(void* arg) { Commander* commander = (Commander*

Prevent OS X from going to sleep with Python?

蹲街弑〆低调 提交于 2019-12-13 13:16:23
问题 Is there a way to prevent a computer running OS X from going to sleep from within a Python script? 回答1: You can call the caffeinate command. subprocess.Popen('caffeinate') This is how I use it: import sys import subprocess if 'darwin' in sys.platform: print('Running \'caffeinate\' on MacOSX to prevent the system from sleeping') subprocess.Popen('caffeinate') 回答2: Since OS 10.6, you have to make use of the IOPMAssertion family of functions, available in Cocoa. This is really well explained

When exactly is onUserInteraction() called?

陌路散爱 提交于 2019-12-13 13:14:52
问题 in my app I got a thrad that checks every 60s data from a webservice (defined in onCreate()): new Thread(new Runnable() { @Override public void run() { while (true) { try { Thread.sleep(PERIOD); if(condition) do_something(); } catch (Exception e) { e.printStackTrace(); } } } }).start(); Additionally i got a handler executing a method after a period of user inactivity: private Handler disconnectHandler = new Handler(); private Runnable disconnectCallback = new Runnable() { @Override public

Python 3.3.3 time.sleep() error [duplicate]

前提是你 提交于 2019-12-13 11:29:58
问题 This question already has answers here : Python: “global name 'time' is not defined” (5 answers) Closed 5 years ago . I'm getting the following error: The error:"Traceback (most recent call last): File "C:\Users\Jamie\Desktop\Python\ATM.py", line 8, in <module> time.sleep(2) NameError: name 'time' is not defined" here is my code: http://pastebin.com/q2v7sdbz Any ideas towards what may be throwing this? Best, Jamie 回答1: the sleep function comes from the python time module so you to import

__sleep() and superclass properties [closed]

折月煮酒 提交于 2019-12-13 11:04:28
问题 It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 8 years ago . Given two classes: class A { private $prop1; } class B extends A { private $prop2; public function __sleep() { return array('prop1','prop2'); } } That will only serialize the value of prop2 as it's a direct

How to write my own Sleep function using just time.After?

↘锁芯ラ 提交于 2019-12-13 09:13:00
问题 I'm trying to write my own sleep function equivalent to time.Sleep using time.After in Go. Here's the code. First attempt: func Sleep(x int) { msg := make(chan int) msg := <- time.After(time.Second * x) } Second attempt: func Sleep(x int) { time.After(time.Second * x) } Both return errors, can someone explain to me how to write a sleep function equivalent to time.Sleep using time.After and if possible when do I use channel? 回答1: time.After() returns you a channel. And a value will be send on