Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
slapos.toolbox
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
7
Merge Requests
7
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nexedi
slapos.toolbox
Commits
bf7454eb
Commit
bf7454eb
authored
Dec 08, 2011
by
Antoine Catton
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add doc test to clean up as example of what could be done
in slapos.toolbox.
parent
7d0b921e
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
37 additions
and
0 deletions
+37
-0
slapos/equeue/__init__.py
slapos/equeue/__init__.py
+37
-0
No files found.
slapos/equeue/__init__.py
View file @
bf7454eb
...
@@ -41,6 +41,43 @@ import sys
...
@@ -41,6 +41,43 @@ import sys
cleanup_data
=
{}
cleanup_data
=
{}
def
cleanup
(
signum
=
None
,
frame
=
None
):
def
cleanup
(
signum
=
None
,
frame
=
None
):
"""Clean up the application using cleanup_data.
It runs :
* .close method on cleanup_data['sockets'] items
* .terminate() method on cleanup_data['subprocesses'] items
* os.unlink() on cleanup_data['paths'] items
>>> import os
>>> def unlink(path): # Mock of unlink
... print "Unlinking %r" % path
>>> os.unlink = unlink
>>> class mock(str): # Mock objects having close and terminate method
... def close(self):
... print "Close %r" % self
... def terminate(self):
... print "Terminate %r" % self
>>> cleanup_data.update(dict(
... sockets=[mock('socket foo'), mock('socket bar')],
... subprocesses=[mock('process foo'), mock('process bar')],
... paths=[mock('path foo'), mock('path bar')],
... ))
>>> try:
... cleanup()
... except SystemExit:
... print 'Exiting...'
... pass
Unlinking 'path foo'
Unlinking 'path bar'
Close 'socket foo'
Close 'socket bar'
Terminate 'process foo'
Terminate 'process bar'
Exiting...
"""
global
cleanup_data
global
cleanup_data
cleanup_functions
=
dict
(
cleanup_functions
=
dict
(
sockets
=
lambda
sock
:
sock
.
close
(),
sockets
=
lambda
sock
:
sock
.
close
(),
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment