Commit b41a7aa0 authored by Antoine Catton's avatar Antoine Catton

Factorize the code of cleanup() function.

parent f96b495b
...@@ -41,24 +41,18 @@ cleanup_data = {} ...@@ -41,24 +41,18 @@ cleanup_data = {}
def cleanup(signum=None, frame=None): def cleanup(signum=None, frame=None):
global cleanup_data global cleanup_data
# Swallow everything ! cleanup_functions = dict(
# XXX-Antoine: We can see a patern on this code sockets=lambda sock: sock.close(),
# it should be factorized. subprocesses=lambda process: process.terminate(),
for sock in cleanup_data.get('sockets', []): paths=lambda filename: os.unlink(filename),
try: )
sock.close() for data, function in cleanup_functions.iteritems():
except: for item in cleanup_data.get(data, []):
pass # Swallow everything !
for process in cleanup_data.get('subprocesses', []): try:
try: function(item)
process.terminate() except:
except: pass
pass
for filename in cleanup_data.get('paths', []):
try:
os.unlink(filename)
except:
pass
signal.signal(signal.SIGTERM, cleanup) signal.signal(signal.SIGTERM, cleanup)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment