strange exceptions.SystemExit in Python 2.7
<p>Here is my code and error message, anyone have any ideas why there are such exception? Thanks.</p>

<p><strong>Source Code</strong>,</p>

<pre><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()
</code></pre>

<p><strong>Error Code</strong>,</p>

<pre><code>in main
tf.app.run error  (&lt;type 'exceptions.SystemExit'&gt;, SystemExit(), &lt;traceback object at 0x10fa33f38&gt;)
</code></pre>

<p>This is expected behavior: <a href="https://github.com/tensorflow/tensorflow/blob/4f9a3a4def1d0e0bcc0c2ca4cd06d993024fd469/tensorflow/python/platform/app.py#L26" rel="nofollow"><code>tf.app.run()</code></a> passes the result of <code>main()</code> to <a href="https://docs.python.org/2/library/sys.html#sys.exit" rel="nofollow"><code>sys.exit()</code></a> (to make it easier to set an edit code), and <code>sys.exit()</code> raises an <a href="https://docs.python.org/2/library/exceptions.html#exceptions.SystemExit" rel="nofollow"><code>exceptions.SystemExit</code></a> exception.</p>

<p>It's important to mention that using <code>tf.app.run()</code> is <strong>completely optional</strong>. Many TensorFlow scripts include it because it is more compatible with the Google Python coding style. However, if you need to customize the logic in your script, you are free to omit <code>tf.app.run()</code>. (The same applies to <code>tf.app.flags</code>.)</p>

python python-2.7 exception tensorflow