exit

Python subprocess: callback when cmd exits

青春壹個敷衍的年華 提交于 2019-11-27 00:13:38
I'm currently launching a programme using subprocess.Popen(cmd, shell=TRUE) I'm fairly new to Python, but it 'feels' like there ought to be some api that lets me do something similar to: subprocess.Popen(cmd, shell=TRUE, postexec_fn=function_to_call_on_exit) I am doing this so that function_to_call_on_exit can do something based on knowing that the cmd has exited (for example keeping count of the number of external processes currently running) I assume that I could fairly trivially wrap subprocess in a class that combined threading with the Popen.wait() method, but as I've not done threading

How to use sys.exit() in Python

▼魔方 西西 提交于 2019-11-26 23:02:59
问题 player_input = '' # This has to be initialized for the loop while player_input != 0: player_input = str(input('Roll or quit (r or q)')) if player_input == q: # This will break the loop if the player decides to quit print("Now let's see if I can beat your score of", player) break if player_input != r: print('invalid choice, try again') if player_input ==r: roll= randint (1,8) player +=roll #(+= sign helps to keep track of score) print('You rolled is ' + str(roll)) if roll ==1: print('You Lose

Close a WP7 application programmatically? [duplicate]

喜你入骨 提交于 2019-11-26 22:57:35
Possible Duplicate: Windows Phone 7 close application How do I programmatically close a WP7 application? Syed Umar Ahmed You can always call an exit by doing this at your landing page use this code on click of your application back button: if (NavigationService.CanGoBack) { while (NavigationService.RemoveBackEntry() != null) { NavigationService.RemoveBackEntry(); } } This will remove back entries from the stack, and you will press a back button it will close the application without any exception. Acknowledging known solutions to provide "Exit" buttons, currently I do not see a compelling

Is it OK to call pthread_exit from main?

情到浓时终转凉″ 提交于 2019-11-26 22:53:07
When I call pthread_exit from main , the program never gets to terminate. I expected the program to finish, since I was exiting the program's only thread, but it doesn't work. It seems hung. #include <stdio.h> #include <stdlib.h> #include <pthread.h> int main(int argc, char *argv[]) { printf("-one-\n"); pthread_exit(NULL); printf("-two-\n"); } Process Explorer shows that the (only) thread is in Wait:DelayExecution state. According to pthread_exit documentation: The process shall exit with an exit status of 0 after the last thread has been terminated. The behavior shall be as if the

Android: Quit application when press back button

老子叫甜甜 提交于 2019-11-26 22:32:00
问题 In my application i want exit from app when press back button, this my code: @Override public void onBackPressed() { new AlertDialog.Builder(this).setIcon(android.R.drawable.ic_dialog_alert).setTitle("Exit") .setMessage("Are you sure you want to exit?") .setPositiveButton("Yes", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { finish(); } }).setNegativeButton("No", null).show(); } it's work correctly but when i exit from app it does

How do I exit a while loop in Java?

只谈情不闲聊 提交于 2019-11-26 22:02:33
What is the best way to exit/terminate a while loop in Java? For example, my code is currently as follows: while(true){ if(obj == null){ // I need to exit here } } Use break : while (true) { .... if (obj == null) { break; } .... } However, if your code looks exactly like you have specified you can use a normal while loop and change the condition to obj != null : while (obj != null) { .... } while(obj != null){ // statements. } break is what you're looking for: while (true) { if (obj == null) break; } alternatively, restructure your loop: while (obj != null) { // do stuff } or: do { // do stuff

Android: Capturing the return of an activity

你。 提交于 2019-11-26 21:29:11
I have a question regarding launching new activities. It boils down to this. I have 3 tabs on a view A) contains gMap activity B) camera activity C) some random text fields. Requirement is that the application runs in Portrait mode. All 3 tabs work as expected w/ the exception of the Camera Preview Surface (B). It is rotated 90 degrees. They only way to make it correct is to set the app to landscape which throws all my tabs around, and is pretty much unworkable. My solution is this : replace my camera activity with a regular activity that is empty w/ the exception of Intent i = new Intent(this

Intercept Tkinter “Exit” command?

浪子不回头ぞ 提交于 2019-11-26 21:23:55
问题 I'm writing a client-server program in Python with Tkinter. I need the server to keep track of the connected clients. For this, I would like to have the client send an automated message to the server after the exit button(the standard "X" in the corner) is clicked. How can I know when the user is exiting the program? 回答1: You want to use the wm_protocol method of the toplevel window. Specifically, you are interested in the WM_DELETE_WINDOW protocol. If you use that method, it allows you to

exit() call inside a function which should return a reference

那年仲夏 提交于 2019-11-26 21:07:19
In a library I have a function which searches for a key in a database and return a non-const reference to an object. I want to handle the case in which the key is not found, which is typically caused by a mistake when calling the function. This situation is so bad that the program cannot continue, so I print a message to help to spot the bug and call exit(1) . The problem is with the return statement which will never be executed in this case, but have to be there anyway. If it was a pointer I could just return nullptr; but with a reference? Should I do something like this pseudo code? Type &