sleep

Can I use `std::this_thread::sleep_for()` with an MPI process?

纵饮孤独 提交于 2019-12-11 13:27:13
问题 MPI runs my program with multiple processes. I'd one of these processes to sleep for a while so that it's using minimal CPU. std::this_thread::sleep_for() looks like what I want, but that thread bit looks a little sketchy in this context. Is it okay to do this? 回答1: This is perfectly OK to do - nothing should crash or hang as a result of it. However, your "so that it's using minimal CPU" is a little worrying. Are you running more MPI processes than you have hardware threads available to

Disable App Nap

巧了我就是萌 提交于 2019-12-11 12:48:46
问题 I really need to disable App Nap in my OS X application in Swift but I've looked all over the web and can't find an answer. Any help would be appreciated. 回答1: Try this: let myQueue = OperationQueue() let myActivity = ProcessInfo.processInfo.beginActivity( options: ProcessInfo.ActivityOptions.userInitiated, reason: "Batch processing files") myQueue.addOperation( { // Perform batch processing of files here ProcessInfo.processInfo.endActivity(myActivity) } ) Read more about App Nap on Apples

Java GUI Not changing

穿精又带淫゛_ 提交于 2019-12-11 11:55:22
问题 Okay so i am making a simple reaction game and my code is as below. Now when startGame() is called, if I comment out the while loop everything happens okay but when I run it with the thread.sleep(1000) the thing is just stuck! the whole program executes and nothing happens. Please take 2 minutes to run the code and help me debug it. I am using the thread.sleep(1000) to see if the the user can click the lit up jPanelArray JPanel. But I believe because of the thread.sleep the GUI doesn't change

Multithreading in python: when does a thread become inactive?

谁说我不能喝 提交于 2019-12-11 10:59:59
问题 This is my code and I am getting varied output. import threading import time def th_fun(limit,sleeptime): print '%s' % (limit) print '%s number of threads are active' % (threading.activeCount()) time.sleep(sleeptime) if __name__ == '__main__': for i in range(5): t = threading.Thread(target = th_fun , args = (i,1)) t.start() Can someone tell when a thread becomes inactive? My understanding is that 5 different thread objects are created and run and as soon as time.sleeptime() is executed it

PHP time delay using ob_flush with loading message

夙愿已清 提交于 2019-12-11 09:28:26
问题 I'm running a PHP script that accesses some MySQL databases, and I need to wait a few seconds until the previous script has entered all the information into the database. The wait time shouldn't be long, but just in case servers are slow on an off day, I'm using sleep(10) to wait 10 seconds before executing the script. I wanted to display a "please wait" message, while it is waiting that 10 seconds, but unfortunately that message gets displayed only after the 10 seconds has already been

Weird behavior in Thread.sleep()

此生再无相见时 提交于 2019-12-11 08:58:18
问题 I have noticed something very odd (which eventually crashes my game) with Thread.sleep() and I cannot figure out what the problem might be. I have run the following method for two hours straight and the output is always 100+-5; public void gameLoop() { t0 = time(); while (GameState.getInstance().getState() == GameCondition.RUNNING) { engine.update(); sfx.play(); t1 = time(); delta = t1 - t0; gfx.render((int) delta); t0 = time(); System.out.println(delta); sleep(100); } } Now if I run the

Producer / Consumer - Producer using high CPU

。_饼干妹妹 提交于 2019-12-11 08:20:46
问题 I have a consumer as part of the producer consumer pattern: simplified: public class MessageFileLogger : ILogger { private BlockingCollection<ILogItem> _messageQueue; private Thread _worker; private bool _enabled = false; public MessageFileLogger() { _worker = new Thread(LogMessage); _worker.IsBackground = true; _worker.Start(); } private void LogMessage() { while (_enabled) { if (_messageQueue.Count > 0) { itm = _messageQueue.Take(); processItem(itm); } else { Thread.Sleep(1000); } } } } If

How to make PhantomJS wait for a specific condition on the page

百般思念 提交于 2019-12-11 07:58:53
问题 I want to realize something like this: function(){ var ua = page.evaluate(function() { while (document.getElementById("td_details87").parentElement.children[11].textContent == "Running" ) { console.log ("running....."); sleep(10000); //10 seconds }; console.log ("DONE"); }); }, How can I realize the sleep function and is there a while loop? 回答1: There is no blocking sleep() function in JavaScript. If you want to sleep then you have to use some asynchronous function like setTimeout(callback,

Pause execution in Java GUI

前提是你 提交于 2019-12-11 07:39:43
问题 I am writing a quiz program for the Android (written in Java). When the user answers a question (by clicking a button), I want to flash a message on the screen saying whether they were correct or not, followed by a 5 second pause before moving on to the next question. However, when an answer button is clicked, the program pauses, but does not display the message of correct/incorrect. The message only comes up once the sleep method has finished. if (correct) Answer.setText("CORRECT!"); else

Running a Laravel method every 30 seconds

◇◆丶佛笑我妖孽 提交于 2019-12-11 07:39:33
问题 I have a method that runs when I call a specific URL on my application. It processes rows in a database queue. The interval is set as lowest interval possible with Cron, ie. 1 minute. This needs dropping to 30 seconds, so I'm wondering how best to achieve this. I was thinking I could build a loop into my script that runs the code twice, with a sleep of say 30 seconds in between, but I'm wondering if there's a cleaner way than this. Also, is there a way of running this method from the command