Commit b41a7aa0 authored by Antoine Catton's avatar Antoine Catton

Factorize the code of cleanup() function.

parent f96b495b
...@@ -41,22 +41,16 @@ cleanup_data = {} ...@@ -41,22 +41,16 @@ cleanup_data = {}
def cleanup(signum=None, frame=None): def cleanup(signum=None, frame=None):
global cleanup_data global cleanup_data
cleanup_functions = dict(
sockets=lambda sock: sock.close(),
subprocesses=lambda process: process.terminate(),
paths=lambda filename: os.unlink(filename),
)
for data, function in cleanup_functions.iteritems():
for item in cleanup_data.get(data, []):
# Swallow everything ! # Swallow everything !
# XXX-Antoine: We can see a patern on this code
# it should be factorized.
for sock in cleanup_data.get('sockets', []):
try: try:
sock.close() function(item)
except:
pass
for process in cleanup_data.get('subprocesses', []):
try:
process.terminate()
except:
pass
for filename in cleanup_data.get('paths', []):
try:
os.unlink(filename)
except: except:
pass pass
......
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