Lin Ma Lin Ma - 2 months ago 23
Python Question

strange exceptions.SystemExit in Python 2.7

Here is my code and error message, anyone have any ideas why there are such exception? Thanks.

Source Code,

import sys
import tensorflow as tf

def main(argv):
print 'in main'
def f():
# this method will call def main(argv)
try:
tf.app.run()
except:
print "tf.app.run error ", sys.exc_info()

if __name__ == "__main__":
f()


Error Code,

in main
tf.app.run error (<type 'exceptions.SystemExit'>, SystemExit(), <traceback object at 0x10fa33f38>)

Answer

This is expected behavior: tf.app.run() passes the result of main() to sys.exit() (to make it easier to set an edit code), and sys.exit() raises an exceptions.SystemExit exception.