sleep

Display a countdown for the python sleep function

萝らか妹 提交于 2020-01-10 10:15:01
问题 I am using time.sleep(10) in my program. Can display the countdown in the shell when I run my program? >>>run_my_program() tasks done, now sleeping for 10 seconds and then I want it to do 10,9,8,7.... is this possible? 回答1: you could always do #do some stuff print 'tasks done, now sleeping for 10 seconds' for i in xrange(10,0,-1): time.sleep(1) print i This snippet has the slightly annoying feature that each number gets printed out on a newline. To avoid this, you can import sys import time

Display a countdown for the python sleep function

喜你入骨 提交于 2020-01-10 10:14:41
问题 I am using time.sleep(10) in my program. Can display the countdown in the shell when I run my program? >>>run_my_program() tasks done, now sleeping for 10 seconds and then I want it to do 10,9,8,7.... is this possible? 回答1: you could always do #do some stuff print 'tasks done, now sleeping for 10 seconds' for i in xrange(10,0,-1): time.sleep(1) print i This snippet has the slightly annoying feature that each number gets printed out on a newline. To avoid this, you can import sys import time

Thread.sleep() is hung?

我怕爱的太早我们不能终老 提交于 2020-01-10 08:49:15
问题 Here's my simple code to loop every second (doesn't need to be exact) and kick off a job if necessary: while (true) { // check db for new jobs and // kick off thread if necessary try { Thread.sleep(1000); } catch(Throwable t) { LOG.error("", t); } } This code has worked fine for several months. Just yesterday we started having problems where one of our servers seems to be hung in the Thread.sleep(1000) method . IOW - it's been over a day and the Thread.sleep hasn't returned. I started up

Trying to simulate constant byte rate. Confusion with time.sleep results

时光总嘲笑我的痴心妄想 提交于 2020-01-10 05:45:08
问题 Context I'm using windows 7 on my computer(the player) and linux(debian) on my college computer(the streamer), which I control using ssh. I was trying to simulate a constant byte rate of a microphone from reading a wave file, as if someone was talking. The problem was that the byte rate was below the target. Choosing a 32KB/s rate, and 0.020 seconds of capture time. I implemented the simulated microphone using time.sleep to produce give each chunk of data each 0.020 seconds. But the rate

Ruby Loop Failing in Thread

江枫思渺然 提交于 2020-01-07 07:14:08
问题 I have a thread in Ruby. It runs a loop. When that loop reaches a sleep(n) it halts and never wakes up. If I run the loop with out sleep(n) it runs as a infinite loop. Whats going on in the code to stop the thread from running as expected? How do i fix it? class NewObject def initialize @a_local_var = 'somaText' end def my_funk(a_word) t = Thread.new(a_word) do |args| until false do puts a_word puts @a_local_var sleep 5 #This invokes the Fail end end end end if __FILE__ == $0 s = NewObject

Skip errors in R for loops and also pause the process in each iteration

假如想象 提交于 2020-01-06 06:52:26
问题 I two questions regarding loops in R . 1) I'm using XML package to scrap some tables from the website and combine them using rbind . I'm using following command and it is working without issues if price data and tables are present in the given websites. url.list <- c("www1", "www2", "www3") for(url_var in url.list) { url <- url_var url.parsed <- htmlParse(getURL(url), asText = TRUE) tableNodes <- getNodeSet(url.parsed, '//*[@id="table"]/table') newdata <- readHTMLTable(tableNodes[[1]], header

Skip errors in R for loops and also pause the process in each iteration

只谈情不闲聊 提交于 2020-01-06 06:52:04
问题 I two questions regarding loops in R . 1) I'm using XML package to scrap some tables from the website and combine them using rbind . I'm using following command and it is working without issues if price data and tables are present in the given websites. url.list <- c("www1", "www2", "www3") for(url_var in url.list) { url <- url_var url.parsed <- htmlParse(getURL(url), asText = TRUE) tableNodes <- getNodeSet(url.parsed, '//*[@id="table"]/table') newdata <- readHTMLTable(tableNodes[[1]], header

Slowing the GUI down in Android

有些话、适合烂在心里 提交于 2020-01-06 04:36:26
问题 My Android App works fine, except the end sequence. Its a game and at the end the screen shows the score: TextView allscores = new TextView(this); allscores.setText("Your score: "+ mypoints); Next I want the GUI to slowdown for a few seconds so the user has time to take in the information. Maybe 2 or 3 secs is fine. try { Thread.sleep(3000); } catch (InterruptedException e) { e.printStackTrace(); } layout.removeAllViews(); Bear in mind, I'm new to thread programming. All this is done on the

Slowing the GUI down in Android

喜欢而已 提交于 2020-01-06 04:36:11
问题 My Android App works fine, except the end sequence. Its a game and at the end the screen shows the score: TextView allscores = new TextView(this); allscores.setText("Your score: "+ mypoints); Next I want the GUI to slowdown for a few seconds so the user has time to take in the information. Maybe 2 or 3 secs is fine. try { Thread.sleep(3000); } catch (InterruptedException e) { e.printStackTrace(); } layout.removeAllViews(); Bear in mind, I'm new to thread programming. All this is done on the

Can't manage to sleep inside a loop

最后都变了- 提交于 2020-01-04 14:04:01
问题 I want to pause 1 second for every time it loops, it is usually easy to do similar pauses on other cases, but when working with loops, it seems it get harder: for (var i=0 ; i < 10 ; i++) { document.write (i + "<br>"); // I want to wait 1 second here } This is one example of my thousands failed attempts: function writeMsg (index) { document.write (index + "<br>"); } for (var i=0 ; i < 10 ; i++) { setTimeout (writeMsg(i), 1000); } Any ideas of how to get this to work? 回答1: This function works