本文整理汇总了Python中sys.exc_value方法的典型用法代码示例。如果您正苦于以下问题:Python sys.exc_value方法的具体用法?Python sys.exc_value怎么用?Python sys.exc_value使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sys
的用法示例。
在下文中一共展示了sys.exc_value方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: ScheduleCategoryUpdate
# 需要导入模块: import sys [as 别名]
# 或者: from sys import exc_value [as 别名]
def ScheduleCategoryUpdate(result_parent_key):
"""Add a task to update a category's statistics.
The task is handled by base.admin.UpdateCategory which then
calls UpdateCategory below.
"""
# Give the task a name to ensure only one task for each ResultParent.
result_parent = ResultParent.get(result_parent_key)
category = result_parent.category
name = 'categoryupdate-%s' % str(result_parent_key).replace('_', '-under-')
url = '/_ah/queue/update-category/%s/%s' % (category, result_parent_key)
task = taskqueue.Task(url=url, name=name, params={
'category': category,
'user_agent_key': result_parent.user_agent.key(),
})
attempt = 0
while attempt < 3:
try:
task.add(queue_name='update-category')
break
except:
attempt += 1
logging.info('Cannot add task(attempt %s): %s:%s' %
(attempt, sys.exc_type, sys.exc_value))
示例2: test_str2
# 需要导入模块: import sys [as 别名]
# 或者: from sys import exc_value [as 别名]
def test_str2(self):
# verify we can assign to sys.exc_*
sys.exc_traceback = None
sys.exc_value = None
sys.exc_type = None
self.assertEqual(str(Exception()), '')
@skipUnlessIronPython()
def test_array(self):
import System
try:
a = System.Array()
except Exception, e:
self.assertEqual(e.__class__, TypeError)
else:
示例3: traceback_get_exception
# 需要导入模块: import sys [as 别名]
# 或者: from sys import exc_value [as 别名]
def traceback_get_exception(num = -1):
# build error message
exception_string = ''.join(traceback.format_exception_only(sys.exc_type, hasattr(sys, 'exc_value') and sys.exc_value or 'Unknown'))
# extract error location from traceback
if hasattr(sys, 'exc_traceback'):
(filename, line_number, function_name, text) = traceback.extract_tb(sys.exc_traceback)[num]
else:
(filename, line_number, function_name, text) = ('-', '-', '-', '-')
error = {
'message': exception_string,
'location': {
'filename': filename,
'line_number': line_number,
'function_name': function_name,
'text': text,
}
}
return error
示例4: run_campaign
# 需要导入模块: import sys [as 别名]
# 或者: from sys import exc_value [as 别名]
def run_campaign(test_campaign, get_interactive_session, verb=2):
passed=failed=0
if test_campaign.preexec:
test_campaign.preexec_output = get_interactive_session(test_campaign.preexec.strip())[0]
for testset in test_campaign:
for t in testset:
t.output,res = get_interactive_session(t.test.strip())
the_res = False
try:
if res is None or res:
the_res= True
except Exception,msg:
t.output+="UTscapy: Error during result interpretation:\n"
t.output+="".join(traceback.format_exception(sys.exc_type, sys.exc_value, sys.exc_traceback,))
if the_res:
t.res = True
res = "passed"
passed += 1
else:
t.res = False
res = "failed"
failed += 1
t.result = res
if verb > 1:
print >>sys.stderr,"%(result)6s %(crc)s %(name)s" % t
示例5: write
# 需要导入模块: import sys [as 别名]
# 或者: from sys import exc_value [as 别名]
def write(self, sock):
why = None
w = self.watcher
self.setEnabled(0)
try:
why = w.doWrite()
except:
why = sys.exc_value
log.msg('Error in %s.doWrite()' % w)
log.deferr()
if why:
self.reactor.removeReader(w)
self.reactor.removeWriter(w)
try:
w.connectionLost(failure.Failure(why))
except:
log.deferr()
elif self.watcher:
self.setEnabled(1)
self.reactor.simulate()
示例6: test_actors
# 需要导入模块: import sys [as 别名]
# 或者: from sys import exc_value [as 别名]
def test_actors(self):
test_pass = []
test_fail = {}
no_test = []
for actor in self.actors:
aut = self.actors[actor]
if aut == "no_test":
no_test.append(actor)
continue
try:
self.test_actor(actor, aut)
test_pass.append(actor)
except AssertionError as e:
test_fail[actor] = e.message
except Exception as e:
self.illegal_actors[actor] = str(e) + '\n' + ''.join(
traceback.format_exception(sys.exc_type, sys.exc_value, sys.exc_traceback))
return {'pass': test_pass, 'fail': test_fail, 'skipped': no_test,
'errors': self.illegal_actors, 'components': self.components}
示例7: ScheduleRecentTestsUpdate
# 需要导入模块: import sys [as 别名]
# 或者: from sys import exc_value [as 别名]
def ScheduleRecentTestsUpdate():
attempt = 0
while attempt < 3:
try:
taskqueue.Task(method='GET').add(queue_name='recent-tests')
break
except:
attempt += 1
logging.info('Cannot add task (attempt %s): %s:%s' %
(attempt, sys.exc_type, sys.exc_value))
示例8: UpdateDirty
# 需要导入模块: import sys [as 别名]
# 或者: from sys import exc_value [as 别名]
def UpdateDirty(request):
"""Updates any dirty tests, adding its score to the appropriate ranker."""
logging.debug('UpdateDirty start.')
task_name_prefix = request.REQUEST.get('task_name_prefix', '')
result_time_key = request.REQUEST.get('result_time_key')
category = request.REQUEST.get('category')
count = int(request.REQUEST.get('count', 0))
if result_time_key:
result_time = ResultTime.get(result_time_key)
try:
ResultTime.UpdateStats(result_time)
except:
logging.info('UpdateStats: %s:%s' % (sys.exc_type, sys.exc_value))
result_parent_key = result_time.parent_key()
else:
result_parent_key = request.REQUEST.get('result_parent_key')
if result_parent_key:
result_parent_key = db.Key(result_parent_key)
else:
UpdateOldDirty()
return http.HttpResponse('Done scheduling old results.')
# Create a task for the next dirty ResultTime to update.
dirty_query = ResultTime.all(keys_only=True)
dirty_query.filter('dirty =', True)
dirty_query.ancestor(result_parent_key)
next_result_time_key = dirty_query.get()
if next_result_time_key:
logging.debug('Schedule next ResultTime: %s', next_result_time_key)
ResultParent.ScheduleUpdateDirty(
next_result_time_key, category, count+1, task_name_prefix)
else:
logging.debug('Done with result_parent: %s', result_parent_key)
ScheduleCategoryUpdate(result_parent_key)
shardedcounter.increment(category)
return http.HttpResponse('Done.')
示例9: ScheduleUpdateDirty
# 需要导入模块: import sys [as 别名]
# 或者: from sys import exc_value [as 别名]
def ScheduleUpdateDirty(cls, result_time_key, category=None, count=0,
task_name_prefix=''):
"""Schedule UpdateStats for a given ResultTime.
This gets handled by base.manage_dirty.UpdateDirty which
then calls ResultTime.UpdateStats().
Args:
result_time_key: a dirty ResultTime key
category: the category string
count: index of ResultTime for logging purposes
task_name_prefix: change a task name to retry tombstoned tasks
"""
result_parent_key = result_time_key.parent()
if not category:
category = cls.get(result_parent_key).category
task = taskqueue.Task(
url='/admin/update_dirty/%s/%s/%d/%s' % (
category, result_parent_key, count, result_time_key),
name='%supdatedirty-%s' % (
task_name_prefix, str(result_time_key).replace('_', '-under-')),
params={'result_time_key': result_time_key, 'category': category,
'count': count})
attempt = 0
while attempt < 3:
try:
task.add(queue_name='update-dirty')
break
except:
attempt += 1
if attempt == 3:
logging.info('Cannot add task: %s:%s' % (sys.exc_type, sys.exc_value))
return False
return True
示例10: print_exc
# 需要导入模块: import sys [as 别名]
# 或者: from sys import exc_value [as 别名]
def print_exc(limit=None, file=None):
"""Shorthand for 'print_exception(sys.exc_type, sys.exc_value, sys.exc_traceback, limit, file)'.
(In fact, it uses sys.exc_info() to retrieve the same information
in a thread-safe way.)"""
if file is None:
file = sys.stderr
try:
etype, value, tb = sys.exc_info()
print_exception(etype, value, tb, limit, file)
finally:
etype = value = tb = None
示例11: runTestFast
# 需要导入模块: import sys [as 别名]
# 或者: from sys import exc_value [as 别名]
def runTestFast(test_name):
'''
Helper function simply imports a test as a module.
'''
#backup sys.stderr/sys.stdout
old_stderr = sys.stderr
old_stdout = sys.stdout
#temporary sys.stdout/sys.stderr
f = open("temp.log", "w")
#return values
ec = 0
errors = ""
try:
#take over sys.stdout/sys.stderr and import the test module
sys.stdout = f
sys.stderr = f
__import__(test_name.split(".py")[0])
except SystemExit:
ec = int(str(sys.exc_value))
except:
ec = 1
finally:
sys.stderr = old_stderr
sys.stdout = old_stdout
f.close()
if ec!=0:
f = open("temp.log", "r")
for line in f.readlines():
errors = errors + line
f.close()
return (ec, errors)
示例12: test_complex_ctor_str
# 需要导入模块: import sys [as 别名]
# 或者: from sys import exc_value [as 别名]
def test_complex_ctor_str(self):
l = [ "-1", "0", "1", "+1", "+1.1", "-1.01", "-.101", ".234", "-1.3e3", "1.09e-3", "33.2e+10"] #, " ", ""] #http://ironpython.codeplex.com/workitem/28385
for s in l:
try:
printwith("case", complex_case_repr(s))
c = complex(s)
printwithtype(c)
except:
printwith("same", sys.exc_type, sys.exc_value)
s += "j"
try:
printwith("case", complex_case_repr(s))
c = complex(s)
printwithtype(c)
except:
printwith("same", sys.exc_type, sys.exc_value)
for s1 in l:
for s2 in l:
try:
if s2.startswith("+") or s2.startswith("-"):
s = "%s%sJ" % (s1, s2)
else:
s = "%s+%sj" % (s1, s2)
printwith("case", complex_case_repr(s))
c = complex(s)
printwithtype(c)
except:
printwith("same", sys.exc_type, sys.exc_value)
示例13: test_complex_ctor
# 需要导入模块: import sys [as 别名]
# 或者: from sys import exc_value [as 别名]
def test_complex_ctor(self):
# None is not included due to defaultvalue issue
ln = [-1, 1L, 1.5, 1.5e+5, 1+2j, -1-9.3j ]
ls = ["1", "1L", "-1.5", "1.5e+5", "-34-2j"]
la = []
la.extend(ln)
la.extend(ls)
for s in la:
try:
printwith("case", complex_case_repr(s))
c = complex(s)
printwithtype(c)
except:
printwith("same", sys.exc_type, sys.exc_value)
for s in la:
try:
printwith("case", "real only", complex_case_repr(s))
c = complex(real=s)
printwithtype(c)
except:
printwith("same", sys.exc_type, sys.exc_value)
for s in la:
try:
printwith("case", "imag only", complex_case_repr(s))
c = complex(imag=s)
printwithtype(c)
except:
printwith("same", sys.exc_type, sys.exc_value)
for s1 in la:
for s2 in ln:
try:
printwith("case", complex_case_repr(s1, s2))
c = complex(s1, s2)
printwithtype(c)
except:
printwith("same", sys.exc_type, sys.exc_value)
示例14: handle_error
# 需要导入模块: import sys [as 别名]
# 或者: from sys import exc_value [as 别名]
def handle_error(self):
self.result = TestResult(False, errorstr(sys.exc_value))
self.close()
示例15: cd
# 需要导入模块: import sys [as 别名]
# 或者: from sys import exc_value [as 别名]
def cd(tdir):
try:
os.chdir(tdir)
except OSError:
ex = sys.exc_value
print ex
return os.getcwd()