Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test(self):
try:
raise
except:
# bar is uninitialized
return Traceback().get_traceback()
def test_empty(self):
self.assertEqual('', get_traceback())
self.assertEqual('', Traceback().get_traceback())
self.assertEqual((None, None, None), Traceback().exc_info)
except KeyboardInterrupt:
thread.stop()
# interrupt otherwise
hub.worker.interrupt_tasks([task.task_id])
return
except SystemExit as ex:
if len(ex.args) > 0 and ex.args[0] != 0:
sys.stdout.write("\nProgram has exited with return code '%s'." % ex.args[0])
failed = True
except FailTaskException as ex:
failed = True
except:
message = "ERROR: %s\n" % kobo.tback.get_exception()
message += "See traceback.log for details (admin only).\n"
hub.upload_task_log(BytesIO(message.encode()), task.task_id, "error.log")
hub.upload_task_log(BytesIO(kobo.tback.Traceback().get_traceback()), task.task_id, "traceback.log", mode=0o600)
failed = True
finally:
thread.stop()
if failed:
hub.worker.fail_task(task.task_id, task.result)
else:
hub.worker.close_task(task.task_id, task.result)
def _hook(exctype, value, tb):
tback = Traceback((exctype, value, tb))
tback.show_locals = True
logger and logger.error(tback.get_traceback())
tback.print_traceback()
print
# sleep for some time
tm.sleep()
except (ShutdownException, KeyboardInterrupt):
# ignore keyboard interrupts and sigterm
signal.signal(signal.SIGINT, signal.SIG_IGN)
signal.signal(signal.SIGTERM, signal.SIG_IGN)
tm.log_info('Exiting...')
tm.shutdown()
tm.log_info('Cleanup done...')
break
except:
# this is a little extreme: log the exception and continue
traceback = Traceback()
tm.log_error(traceback.get_traceback())
tm.sleep()
raise
if not os.path.isdir(logdir):
os.makedirs(logdir)
# create a file name from function name, date, time and some random characters
file_name = "%s_%s_%s" % (
function.__name__,
datetime.datetime.strftime(datetime.datetime.now(), "%Y-%m-%d_%H-%M-%S"),
random_string(32),
)
# create a file with 0600 perms (log can contain sensitive information like passwords)
file_path = os.path.join(logdir, file_name)
fd = os.open(file_path, os.O_CREAT | os.O_WRONLY, 0o600)
os.write(fd, Traceback().get_traceback())
os.close(fd)
raise
return result