Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
cc-node
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Analyze
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Mirror
cc-node
Commits
738918f4
Commit
738918f4
authored
12 years ago
by
Anael Beutot
Browse files
Options
Downloads
Patches
Plain Diff
Added helper functions for logging fatal error in ForkedJob
parent
b4d3d8a9
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
cloudcontrol/node/jobs.py
+43
-0
43 additions, 0 deletions
cloudcontrol/node/jobs.py
with
43 additions
and
0 deletions
cloudcontrol/node/jobs.py
+
43
−
0
View file @
738918f4
...
...
@@ -5,7 +5,9 @@ import resource
import
signal
import
subprocess
import
sys
import
traceback
from
threading
import
Thread
,
Event
from
StringIO
import
StringIO
from
cloudcontrol.node.exc
import
JobError
from
cloudcontrol.node.utils
import
num_to_sig
...
...
@@ -181,6 +183,47 @@ class ForkedJob(object):
# overide in sub class
pass
def
fatal
(
self
,
fmt
,
*
args
,
**
kwargs
):
"""
Write error message in stderr and exit.
:param str fmt: format string
:param \*args: arguments for format string
:param \*\*kwargs: can contain (
'
status
'
, :int:) -> exit status of process
"""
try
:
status
=
int
(
kwargs
.
get
(
'
status
'
,
1
))
except
(
ValueError
,
TypeError
):
sys
.
stderr
.
write
(
'
Bad status argument %s
'
%
status
)
os
.
_exit
(
42
)
try
:
fmt
=
fmt
%
args
except
(
ValueError
,
TypeError
):
sys
.
stderr
.
write
(
'
Bad formatting for string: %s
'
%
fmt
)
os
.
_exit
(
42
)
try
:
sys
.
stderr
.
write
(
fmt
)
except
IOError
:
os
.
_exit
(
42
)
os
.
_exit
(
status
)
def
fatal_exc
(
self
,
fmt
,
*
args
,
**
kwargs
):
"""
Write error message and traceback and exit.
:param str fmt: format string
:param \*args: arguments for format string
:param \*\*kwargs: can contain (
'
status
'
, :int:) -> exit status of process
"""
tb
=
StringIO
()
tb
.
write
(
'
\n
'
)
traceback
.
print_exc
(
file
=
tb
)
tb
.
write
(
'
\n
'
)
fmt
+=
'
%s
'
args
=
args
+
(
tb
.
getvalue
(),)
self
.
fatal
(
fmt
,
*
args
,
status
=
kwargs
.
get
(
'
status
'
,
1
))
def
close_fds
(
self
):
"""
Close all fds uneeded fds in children.
"""
# get max fd
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment