terminate

How to properly stop a multi-threaded .NET windows service?

Deadly 提交于 2019-11-29 22:20:53
I have a windows service written in C# that creates a truck load of threads and makes many network connections (WMI, SNMP, simple TCP, http). When attempting to stop the windows service using the Services MSC snap-in, the call to stop the service returns relatively quickly but the process continues to run for about 30 seconds or so. The primary question is what could be the reason that it is taking 30+ seconds to stop. What can I look for and how do I go about looking for it? The secondary question is why is the service msc snap-in (service controller) returning even though the process is

Android - Perfect solution for quitting or terminating an application programmatically?

北城余情 提交于 2019-11-29 18:15:56
If my app encounters a particular error, I want to end my app without any trace of it remaining in the system. I have already seen many threads on this topic, specially these two. Is quitting an application frowned upon? How to quit android application programmatically The answers are great but the proposed solutions are too tedious and/or unnecessarily complex. Taking a cue from Neil Traft's answer in the first post above, I have found a perfect solution for such scenarios. System.exit(0) or android.os.Process.killProcess(android.os.Process.myPid()) both seem to work if you have only one

Python Process won't call atexit

跟風遠走 提交于 2019-11-29 13:23:05
I'm trying to use atexit in a Process , but unfortunately it doesn't seem to work. Here's some example code: import time import atexit import logging import multiprocessing logging.basicConfig(level=logging.DEBUG) class W(multiprocessing.Process): def run(self): logging.debug("%s Started" % self.name) @atexit.register def log_terminate(): # ever called? logging.debug("%s Terminated!" % self.name) while True: time.sleep(10) @atexit.register def log_exit(): logging.debug("Main process terminated") logging.debug("Main process started") a = W() b = W() a.start() b.start() time.sleep(1) a.terminate

What is the standard way to get a Rust thread out of blocking operations?

China☆狼群 提交于 2019-11-29 11:21:12
Coming from Java, I am used to idioms along the lines of while (true) { try { someBlockingOperation(); } catch (InterruptedException e) { Thread.currentThread.interrupt(); // re-set the interrupted flag cleanup(); // whatever is necessary break; } } This works, as far as I know, across the whole JDK for anything that might block, like reading from files, from sockets, from a queue and even for Thread.sleep() . Reading on how this is done in Rust, I find lots of seemingly special solutions mentioned like mio , tokio . I also find ErrorKind::Interrupted and tried to get this ErrorKind with

Terminate subprocess in Windows, access denied

▼魔方 西西 提交于 2019-11-29 06:48:09
- import time import subprocess from os.path import expanduser chrome_path = expanduser('~\Local Settings\Application Data\Google\Chrome\Application\chrome.exe') proc = subprocess.Popen(chrome_path) time.sleep(4) proc.terminate() Output: WindowsError: [Error 5] Access is denied How can I kill the Chrome process? Python 2.6 on Windows XP. what happens if you use TASKKILL /F /PID [number of process ID] ? Give it a try. Launch it through import OS I don't know about Windows, but have noticed on Linux that Google Chrome "protects" itself from operating system control signals in a way that few

How can I end a Lua thread cleanly?

廉价感情. 提交于 2019-11-29 02:31:40
My situation is that I'm using the Lua (C) API to execute a script held in a string. I would like the user to be able to terminate the execution of the script (this is essential if the script contains an infinite loop), how can I do this? lua_State *Lua = lua_open(); char * code; // Initialisation code luaL_dostring(L, code); You can use a hook to callback to C every time lua executes a line of the script. In this hook function you can check if the user wanted to quit, and call lua_error if they did. static bool ms_quit = false; void IWantToQuit() { ms_quit = true; } void LineHookFunc(lua

Process.HasExited returns true even though process is running?

前提是你 提交于 2019-11-28 22:37:12
I have been observing that Process.HasExited sometimes returns true even though the process is still running. My code below starts a process with name "testprogram.exe" and then waits for it to exit. The problem is that sometimes I get thrown the exception; it seems that even though HasExited returns true the process itself is still alive in the system - how can this be?? My program writes to a log file just before it terminates and thus I need to be absolutely sure that this log file exists (aka the process has terminated/finished) before reading it. Continuously checking for it's existence

How terminate child processes when parent process terminated in C#

五迷三道 提交于 2019-11-28 20:39:14
Task: Auto kill all child processes if parent process terminate. Parent procees can be terminated not only in correct way, but also by killing in ProcessExplorer, for example. How can I do it? Similar question in С topic advice to use Job objects. How to use it in C# without exporting external DLL? I tried to use Job Objects. But this code doesn't work properly: var job = PInvoke.CreateJobObject(null, null); var jobli = new PInvoke.JOBOBJECT_BASIC_LIMIT_INFORMATION(); jobli.LimitFlags = PInvoke.LimitFlags.JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE | PInvoke.LimitFlags.JOB_OBJECT_LIMIT_PRIORITY_CLASS |

How to stop/terminate a python script from running?

核能气质少年 提交于 2019-11-28 20:03:44
I wrote a program in IDLE to tokenize text files and it starts to tokeniza 349 text files! How can I stop it? How can I stop a running Python program? To stop your program, just press Control + C . You can also do it if you use the exit() function in your code. More ideally, you can do sys.exit() . sys.exit() might terminate Python even if you are running things in parallel through the multiprocessing package. Ctrl-Break it is more powerful than Ctrl-C wpp To stop a python script just press Ctrl + C . Inside a script with exit() , you can do it. You can do it in an interactive script with just

How to properly stop a multi-threaded .NET windows service?

人盡茶涼 提交于 2019-11-28 19:54:14
问题 I have a windows service written in C# that creates a truck load of threads and makes many network connections (WMI, SNMP, simple TCP, http). When attempting to stop the windows service using the Services MSC snap-in, the call to stop the service returns relatively quickly but the process continues to run for about 30 seconds or so. The primary question is what could be the reason that it is taking 30+ seconds to stop. What can I look for and how do I go about looking for it? The secondary