resource-cleanup

Intercepting application close in c#

I'd like to properly close some sockets, and be able to tell the server that we're closing, but if the application is closed then the sockets are all just closed and on occasion files are left locked. How can I run a method when my application is closed? This is going to go into a library that will be used in a forms app. ...

How can I get around the lack of a finally block in PHP?

PHP has no finally block - i.e., whereas in most sensible languages, you can do: try { //do something } catch(Exception ex) { //handle an error } finally { //clean up after yourself } PHP has no notion of a finally block. Anyone have experience of solutions to this rather irritating hole in the language? ...

Python's Popen cleanup

I wanted to use a python equivalent to piping some shell commands in perl. Something like the python version of open(PIPE, "command |"). I go to the subprocess module and try this: p = subprocess.Popen("zgrep thingiwant largefile", shell=True, stdout=subprocess.PIPE) This works for reading the output the same way I would in perl, bu...