wait

Go的sync.WaitGroup(二)

故事扮演 提交于 2019-11-29 06:23:15
WaitGroup add与done只是用来统计数量的 done减为0的时候就告诉wait结束 wait只是用来堵塞主函数的 当协程数为0时候结束 有了它我们不用写time.Sleep或者<-channelname了 package main import ( "fmt" "sync" ) var waitgroup sync.WaitGroup func Afunction(shownum int) { fmt.Println(shownum) waitgroup.Done() //任务完成,将任务队列中的任务数量-1,其实.Done就是.Add(-1) } func main() { for i := 0; i < 6; i++ { waitgroup.Add(1) //每创建一个goroutine,就把任务队列中任务的数量+1 go Afunction(i) } waitgroup.Wait() //.Wait()这里会发生阻塞,直到队列中所有的任务结束就会解除阻塞 } // 5 // 3 // 2 // 0 // 1 // 4 来源: https://blog.csdn.net/fujian9544/article/details/100538199

Displaying wait cursor in while backgroundworker is running

耗尽温柔 提交于 2019-11-29 06:19:14
问题 During the start of my windows application, I have to make a call to a web service to retrieve some default data to load onto my application. During the load of the form, I run a backgroundworker to retrieve this data. I want to display the wait cursor until this data is retrieved. How would I do this? I've tried setting the wait cursor before calling the backgroundworker to run. When I report a progress of 100 then I set it back to the default cursor. The wait cursor comes up but when I move

Just check status process in c

百般思念 提交于 2019-11-29 05:15:13
I want to know the status of a process. I think I can use the wait family functions but actually I don't want to wait for the process, just check the status and go on. I would want something like checkStatusOfProcess(&status); if(status == WORKING) { //do something } else if(status == exited) { //do something else } else \\I dont care about other states Then you want to use the waitpid function with the WNOHANG option: #include <sys/types.h> #include <sys/wait.h> int status; pid_t return_pid = waitpid(process_id, &status, WNOHANG); /* WNOHANG def'd in wait.h */ if (return_pid == -1) { /* error

Why doesn't thread wait for notify()?

廉价感情. 提交于 2019-11-29 05:07:04
Why doesn't thread wait for notify() ? The thread starts and then goes to the waiting pool, but it proceeds to execute after that moment. public class JavaApplication2 { public static void main(String [] args) { ThreadB b = new ThreadB(); synchronized(b) { b.start(); try { System.out.println("1"); b.wait(); } catch (InterruptedException e) {} System.out.println("Total is: " + b.total); } } } class ThreadB extends Thread { int total; @Override public void run() { synchronized(this) { total += 1; //notify(); } } } You are synchronizing on the thread object itself, which is wrong usage. What

Java Delay/Wait

谁说胖子不能爱 提交于 2019-11-29 03:37:54
How do I delay a while loop to 1 second intervals without slowing down the entire code / computer it's running on to the one second delay (just the one little loop). Thread.sleep(1000); // do nothing for 1000 miliseconds (1 second) It seems your loop runs on Main thread and if you do sleep on that thread it will pause the app (since there is only one thread which has been paused), to overcome this you can put this code in new Thread that runs parallely try{ Thread.sleep(1000); }catch(InterruptedException ex){ //do stuff } My simple ways to delay a loop. I already put the codes here after

Do I need to do anything with a SIGCHLD handler if I am just using wait() to wait for 1 child to finish at a time?

牧云@^-^@ 提交于 2019-11-29 02:44:21
I've got a program that is forking to a child to do some work, but I am only doing one child at a time at this time. I am using wait() to wait for the child to finish, do I need to do anything with SIGCHLD as well (such as disable the handler)? In my situation I am getting a value of EINTR in errno which leads me to think that I need to mask SIGCHLD . In broad strokes, this is the program: read arguments for(list of work to do) fork() if child, execlp() to work program if parent, wait() for child to finish when child finishes, parent loops to next work item Theory POSIX says about SIG_IGN

Python wait x secs for a key and continue execution if not pressed

廉价感情. 提交于 2019-11-29 02:28:26
I'm a n00b to python, and I'm looking a code snippet/sample which performs the following: Display a message like "Press any key to configure or wait X seconds to continue" Wait, for example, 5 seconds and continue execution, or enter a configure() subroutine if a key is pressed. Thank you for your help! Yvan Janssens If you're on Unix/Linux then the select module will help you. import sys from select import select print "Press any key to configure or wait 5 seconds..." timeout = 5 rlist, wlist, xlist = select([sys.stdin], [], [], timeout) if rlist: print "Config selected..." else: print "Timed

Waiting for a specified duration in Cocoa

橙三吉。 提交于 2019-11-29 01:45:49
问题 Is there a more straightforward way to wait for a specific amount of time in Cocoa than what I have come up with below? - (void) buttonPressed { [self makeSomeChanges]; // give the user some visual feedback and wait a bit so he can see it [self displayThoseChangesToTheUser]; [self performSelector:@selector(buttonPressedPart2:) withObject:nil afterDelay:0.35]; } - (void) buttonPressedPart2: (id)unused { [self automaticallyReturnToPreviousView]; } Just to be clear, there is no functional

Python wait until data is in sys.stdin

谁说我不能喝 提交于 2019-11-29 01:42:56
my problem is the following: My pythons script receives data via sys.stdin, but it needs to wait until new data is available on sys.stdin. As described in the manpage from python, i use the following code but it totally overloads my cpu. #!/usr/bin/python -u import sys while 1: for line in sys.stdin.readlines(): do something useful Is there any good way to solve the high cpu usage? Edit: All your solutions don't work. I give you exactly my problem. You can configure the apache2 daemon that he sends every logline to a program and not to write in a logfile. This looks something like that:

Lua - get command line input from user?

心不动则不痛 提交于 2019-11-29 01:26:28
In my lua program, i want to stop and ask user for confirmation before proceeding with an operation. I'm not sure how to stop and wait for user input, how can it be done? Take a look at the io library, which by default has standard-input as the default input file: http://www.lua.org/pil/21.1.html local answer repeat io.write("continue with this operation (y/n)? ") io.flush() answer=io.read() until answer=="y" or answer=="n" Scythe I've worked with code like this. I will type this in a way it will work: io.write("continue with this operation (y/n)?") answer=io.read() if answer=="y" then --(put