Re: Notifications when process is killed
On Aug 1, 11:39 am, Andrea Di Mario wrote: > Thanks Thomas, it is what i'm looking for. > > Regards > > -- > Andrea Di Mario Catch a Kill: def signal_handler(signal, frame): print "Received exit command." #server.running = False sys.exit() signal.signal(signal.SIGINT, signal_handler) signal.signal(signal.SIGTERM, signal_handler) Find and Kill A Process: import os, signal process = "websocket.py" found = False for line in os.popen("ps ax | grep python"): fields = line.split() pid = fields[0] for field in fields: if field.find(process) >= 0: print pid print field os.kill(int(pid), signal.SIGTERM) found = True break if found == True: break if found == True: print "found and killed web server process." else: print "could not find web server process. -- http://mail.python.org/mailman/listinfo/python-list
Re: Notifications when process is killed
On Aug 1, 5:56 am, Andrea Di Mario wrote: > Hi, i've created a twisted server application and i want that the > server send me a message when someone stops or kills the process. > I want to override reactor.stop(), but do this way send me message > when the process is stopped by a system kill? > Could you suggest me if there's a way to do this? > > Thanks, regards. > > -- > Andrea Di Mario This will catch Ctrl+C and a Kill PID request: # Add SIGINT handler for killing the threads def signal_handler(signal, frame): print "Received exit command." server.running = False sys.exit() signal.signal(signal.SIGINT, signal_handler) signal.signal(signal.SIGTERM, signal_handler) And this will find an destroy a process: import os, signal process = "websocket.py" found = False for line in os.popen("ps ax | grep python"): fields = line.split() pid = fields[0] for field in fields: if field.find(process) >= 0: print pid print field os.kill(int(pid), signal.SIGTERM) found = True break if found == True: break if found == True: print "found and killed web server process." else: print "could not find web server process." -- http://mail.python.org/mailman/listinfo/python-list
HID Device Drivers for OS X
Hi, I spent almost all day trying to figure out how to capture a click from this button: http://www.dreamcheeky.com/big-red-button I tried libusb, PyUSB, HIDAPI and probably a couple other things. No luck. My understanding is that libusb won't allow me to get at the interface and the example I found using PyUSB to read a magnetic card reader errors with a segmentation fault in the libusb library. Can anyone point me in the right direction? I looked the OS X I/O Kit at developer.apple.com, but it seems really confusing and over kill. I have the vendor ID and product ID, it seems like it would be really simple to read when the button is clicked. Any thoughts? -- http://mail.python.org/mailman/listinfo/python-list