terminate

Performing an action upon unexpected exit python

旧城冷巷雨未停 提交于 2019-12-04 20:38:14
I was wandering if there was a way to perform an action before the program closes. I am running a program over a long time and I do want to be able to close it and have the data be saved in a text file or something but there is no way of me interfering with the while True loop I have running, and simply saving the data each loop would be highly ineffective. So is there a way that I can save data, say a list, when I hit the x or destroy the program? I have been looking at the atexit module but have had no luck, except when I set the program to finish at a certain point. def saveFile(list):

Terminate python threads using sys.exit()

大憨熊 提交于 2019-12-04 20:01:23
I am looking for a way to terminate a thread by using sys.exit(). I have two functions add1() and subtract1() , which are executed by each thread t1 and t2 respectively. I want to terminate t1 after finishing add1() and t2 after finishing subtract1() . I could see that sys.exit() do that work. Is it ok to do in such way? import time, threading,sys functionLock = threading.Lock() total = 0; def myfunction(caller,num): global total, functionLock functionLock.acquire() if caller=='add1': total+=num print"1. addition finish with Total:"+str(total) time.sleep(2) total+=num print"2. addition finish

Terminate loopless thread instantly without Abort or Suspend

自作多情 提交于 2019-12-04 16:00:00
I am implementing a protocol library. Here a simplified description. The main thread within the main function will always check, whether some data is available on the the networkstream (within a tcpclient). Let us say response is the received message and thread is a running thread. thread = new Thread(new ThreadStart(function)); thread.IsBackground = true; thread.Start(); while(true){ response = receiveMessage(); if (response != null) { thread.Suspend(); //I am searching for an alternative for the line above and not thread.Abort(). thread2 = new Thread(new ThreadStart(function2)); thread2

UIApplicationExitsOnSuspend anything else I'm missing?

▼魔方 西西 提交于 2019-12-04 12:01:51
问题 So I know this has been beaten to death but I still can't figure out a solution. I have my UIApplicationExitsOnSuspend set to <true/> in the Info.plist and still both in the simulator as well as on an iPhone 4 device, the app goes into standby instead of terminating? Any ideas of what else could one do to get it to terminate? Perhaps are there methods that I need to remove from the app delegate? Any ideas? 回答1: Did you do a clean build, delete the app from both the simulator and the device,

Terminate a process by Cocoa

心不动则不痛 提交于 2019-12-04 11:18:42
If I terminate myself, just use the [NSApp terminate: nil] , it works very well. But if I want to terminate another process such as the active monitor, what should I do? To get the list of processes, I use NSArray* processlist = [[NSWorkspace sharedWorkspace] runningApplications]; Am I right? But how I can terminate a process by Cocoa, not use the kill or KillProcess(<#const ProcessSerialNumber *inProcess#>) or killpd or something like those, I just start learning Cocoa, so maybe I need some simple sample code or some keywords that can help me to find the documents. Thank you for your help.

When does background threads prevent the process of being terminated?

被刻印的时光 ゝ 提交于 2019-12-04 06:57:01
Our program creates a background thread at the beginning of the program. The background thread does some database integrity checks and checks for stuff in the Internet using Indy. After 10 seconds, the background thread should be finished and since FreeOnTerminate is true, it will also clean itself up. We have noticed that in some cases, if the user closes the program too quickly, the process will still be alive until the background thread is finished. Since we couldn't exactly reproduce the issue, I have created a demo project to try a few things: type TBackgroundThread = class(TThread)

Rserve server: how to terminate a blocking instance (eval taking forever)?

≯℡__Kan透↙ 提交于 2019-12-04 05:31:10
I need to perform R eval s in a multi-threaded way, which is something Rserve provides quite well. But, if the eval of one instance takes too long, I need to be able to shutdown the instance which is computing the blocking eval. As far as I tested, the given instance will refuse to shutdown until the eval is done (apparently, it needs to fetch the result, before listening again). So here is my question: Is there a way get a java handle on the blocking instance (something like a Process object), such that I can brute force kill/terminate the eval (something like process.destroy() )? In other

In which cases does program exit with 0x40010004 code?

↘锁芯ラ 提交于 2019-12-04 03:19:08
My program is designed to run on Windows platform. Sometimes it terminates with error. I could not debug it on each computer where it is installed; so I added vectored exception handler to it which sends some information about exception to server. There were some 0xC0000005 exceptions; I fixed it, but program still terminates (I could not reproduce error on my PC). I wrote another program, which waits on main process handle, and sends report with process exit code when main process terminates. I looked at exit codes, and most of them were 0x40010004 ( DBG_TERMINATE_PROCESS ). I know that this

Terminating Another App Running - Cocoa

荒凉一梦 提交于 2019-12-03 15:46:17
How can I terminate another app that is running in cooca. Let's say I have iTunes running, and I type in quit in my app, it would quit itunes. "iTunes" is just an example, it could be anything the user wants. I can open any app from my application, but I want to know how to close any app running. thanks kevin If you're running on Mac OS X 10.6, Snow Leopard, you can use the new NSRunningApplication terminate method. AppleScript is a pretty high-level way to send a single Quit event. SIGTERM is a pretty brute-force, low-level way. The correct way to quit another application is to obtain its

Which is the proper way to terminate a delphi application?

佐手、 提交于 2019-12-03 15:12:03
问题 I would like to terminate a Delphi application without executing any other code line and I'm wondering about which is the proper way to do this. Furthermore, I would like to know if there's something wrong in what I'm actually doing at the moment. Basically, my code looks like this: //Freeing all objects (Obj1.Free, etc..) Application.Terminate; Halt; Is this the right way to stop a Delphi application or should it be done in another way? 回答1: Application.Terminate() breaks the message loops