本文整理匯總了Python中sys.exc_type方法的典型用法代碼示例。如果您正苦於以下問題:Python sys.exc_type方法的具體用法?Python sys.exc_type怎麽用?Python sys.exc_type使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類sys
的用法示例。
在下文中一共展示了sys.exc_type方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: ScheduleCategoryUpdate
# 需要導入模塊: import sys [as 別名]
# 或者: from sys import exc_type [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_set
# 需要導入模塊: import sys [as 別名]
# 或者: from sys import exc_type [as 別名]
def test_set(self):
side1 = [ None, set(), set('a'), set('abc'), set('bde')]
for x in side1:
for y in side1:
for func in funclist2:
try:
printwith("case", case_repr(x, y, func));
res = func(x, y)
printwith("case", res)
if isinstance(res, set):
for c in 'abcde':
printwith("same", c in res)
else:
printwith("same", res)
except:
printwith("same", sys.exc_type)
示例3: test_reload_sys
# 需要導入模塊: import sys [as 別名]
# 或者: from sys import exc_type [as 別名]
def test_reload_sys(self):
import sys
(old_copyright, old_byteorder) = (sys.copyright, sys.byteorder)
(sys.copyright, sys.byteorder) = ("foo", "foo")
(old_argv, old_exc_type) = (sys.argv, sys.exc_type)
(sys.argv, sys.exc_type) = ("foo", "foo")
reloaded_sys = reload(sys)
# Most attributes get reset
self.assertEqual((old_copyright, old_byteorder), (reloaded_sys.copyright, reloaded_sys.byteorder))
# Some attributes are not reset
self.assertEqual((reloaded_sys.argv, reloaded_sys.exc_type), ("foo", "foo"))
# Put back the original values
(sys.copyright, sys.byteorder) = (old_copyright, old_byteorder)
(sys.argv, sys.exc_type) = (old_argv, old_exc_type)
示例4: test_str2
# 需要導入模塊: import sys [as 別名]
# 或者: from sys import exc_type [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:
示例5: traceback_get_exception
# 需要導入模塊: import sys [as 別名]
# 或者: from sys import exc_type [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
示例6: run_campaign
# 需要導入模塊: import sys [as 別名]
# 或者: from sys import exc_type [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
示例7: test_0
# 需要導入模塊: import sys [as 別名]
# 或者: from sys import exc_type [as 別名]
def test_0(self):
b = "sys.exc_type"
a = "sys.exc_info()[0]"
self.check(b, a)
示例8: test_3
# 需要導入模塊: import sys [as 別名]
# 或者: from sys import exc_type [as 別名]
def test_3(self):
b = "sys.exc_type # Foo"
a = "sys.exc_info()[0] # Foo"
self.check(b, a)
示例9: test_4
# 需要導入模塊: import sys [as 別名]
# 或者: from sys import exc_type [as 別名]
def test_4(self):
b = "sys. exc_type"
a = "sys. exc_info()[0]"
self.check(b, a)
示例10: test_5
# 需要導入模塊: import sys [as 別名]
# 或者: from sys import exc_type [as 別名]
def test_5(self):
b = "sys .exc_type"
a = "sys .exc_info()[0]"
self.check(b, a)
示例11: FormatException
# 需要導入模塊: import sys [as 別名]
# 或者: from sys import exc_type [as 別名]
def FormatException(message):
"""Adds more information to the exception."""
message = ('Exception Type: %s\n'
'Details: %s\n'
'Message: %s\n') % (sys.exc_type, traceback.format_exc(), message)
return message
示例12: ScheduleRecentTestsUpdate
# 需要導入模塊: import sys [as 別名]
# 或者: from sys import exc_type [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))
示例13: UpdateDirty
# 需要導入模塊: import sys [as 別名]
# 或者: from sys import exc_type [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.')
示例14: ScheduleUpdateDirty
# 需要導入模塊: import sys [as 別名]
# 或者: from sys import exc_type [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
示例15: print_exc
# 需要導入模塊: import sys [as 別名]
# 或者: from sys import exc_type [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