# Help with Exception, org.python.core.PyException: SystemExit: 0

**URL:** <https://forum.inductiveautomation.com/t/help-with-exception-org-python-core-pyexception-systemexit-0/57206>\
**Category:** Ignition\
**Tags:** ignition81, scripting, perspective\
**Created:** [March 15, 2022, 2:00pm UTC](https://forum.inductiveautomation.com/t/help-with-exception-org-python-core-pyexception-systemexit-0/57206 "2022-03-15T14:00:32Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![MikeAllgood](https://avatars.discourse-cdn.com/v4/letter/m/a183cd/32.png) [@MikeAllgood](https://forum.inductiveautomation.com/u/MikeAllgood)\
**Post date:** [March 15, 2022, 2:00pm UTC](https://forum.inductiveautomation.com/t/help-with-exception-org-python-core-pyexception-systemexit-0/57206/1 "2022-03-15T14:00:32Z")

</div>

In our Validation system we have seen the below error a few times, though is seems to be intermittent, and I’d like to get some help deciphering this if possible.  
This is being generated by a script on a button in an embedded view. The button script calls a project script library function the essentially triggers a micrometer to carry out measurement tasks. Though we get this error, it seems like the part measurement carries on as expected. The micrometer is setup as a TCP Driver Device and is one of four different micrometers. We have only seen this error for the #2 micrometer, but we have only recently put any of the others to use.  
We are using v8.1.10 of Ignition.  
Any information as to the meaning of the error content would be helpful as I am at a bit of a loss as to how to track down the root cause of this error.  
Thanks.

```auto
com.inductiveautomation.ignition.common.script.JythonExecException: SystemExit: 0
at org.python.core.PySystemState.exit(PySystemState.java:1619)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.base/java.lang.reflect.Method.invoke(Unknown Source)
at org.python.core.PyReflectedFunction. __call__ (PyReflectedFunction.java:190)
at org.python.core.PyReflectedFunction. __call__ (PyReflectedFunction.java:208)
at org.python.core.PyObject. __call__ (PyObject.java:477)
at org.python.core.PyObject. __call__ (PyObject.java:481)
at org.python.core.PyMethod. __call__ (PyMethod.java:141)
at org.python.pycode._pyx15159.switchMicrometerProgram$8(:524)
at org.python.pycode._pyx15159.call_function()
at org.python.core.PyTableCode.call(PyTableCode.java:173)
at org.python.core.PyBaseCode.call(PyBaseCode.java:150)
at org.python.core.PyFunction. __call__ (PyFunction.java:426)
at org.python.pycode._pyx15798.runAction$1(:22)
at org.python.pycode._pyx15798.call_function()
at org.python.core.PyTableCode.call(PyTableCode.java:173)
at org.python.core.PyBaseCode.call(PyBaseCode.java:306)
at org.python.core.PyFunction.function ___call__ (PyFunction.java:474)
at org.python.core.PyFunction. __call__ (PyFunction.java:469)
at org.python.core.PyFunction. __call__ (PyFunction.java:464)
at com.inductiveautomation.ignition.common.script.ScriptManager.runFunction(ScriptManager.java:849)
at com.inductiveautomation.ignition.common.script.ScriptManager.runFunction(ScriptManager.java:831)
at com.inductiveautomation.ignition.gateway.project.ProjectScriptLifecycle$TrackingProjectScriptManager.runFunction(ProjectScriptLifecycle.java:689)
at com.inductiveautomation.ignition.common.script.ScriptManager$ScriptFunctionImpl.invoke(ScriptManager.java:1000)
at com.inductiveautomation.ignition.gateway.project.ProjectScriptLifecycle$AutoRecompilingScriptFunction.invoke(ProjectScriptLifecycle.java:754)
at com.inductiveautomation.perspective.gateway.script.ScriptFunctionHelper.invoke(ScriptFunctionHelper.java:133)
at com.inductiveautomation.perspective.gateway.action.ScriptAction.runAction(ScriptAction.java:71)
at com.inductiveautomation.perspective.gateway.action.ActionDecorator.runAction(ActionDecorator.java:18)
at com.inductiveautomation.perspective.gateway.action.SecuredAction.runAction(SecuredAction.java:44)
at com.inductiveautomation.perspective.gateway.model.ActionCollection$ActionSequence$ExecuteActionsTask.lambda$call$0(ActionCollection.java:263)
at com.inductiveautomation.perspective.gateway.api.LoggingContext.mdc(LoggingContext.java:54)
at com.inductiveautomation.perspective.gateway.model.ActionCollection$ActionSequence$ExecuteActionsTask.call(ActionCollection.java:252)
at com.inductiveautomation.perspective.gateway.model.ActionCollection$ActionSequence$ExecuteActionsTask.call(ActionCollection.java:221)
at com.inductiveautomation.perspective.gateway.threading.BlockingTaskQueue$TaskWrapper.run(BlockingTaskQueue.java:154)
at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
at java.base/java.util.concurrent.FutureTask.run(Unknown Source)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.base/java.lang.Thread.run(Unknown Source)
Caused by: org.python.core.PyException: SystemExit: 0
... 41 common frames omitted

```

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [March 15, 2022, 2:10pm UTC](https://forum.inductiveautomation.com/t/help-with-exception-org-python-core-pyexception-systemexit-0/57206/2 "2022-03-15T14:10:30Z")

</div>

Looks to me like you’re calling `exit()` from a Perspective script action?

---

<div class="post-metadata">

**Author:** ![MikeAllgood](https://avatars.discourse-cdn.com/v4/letter/m/a183cd/32.png) [@MikeAllgood](https://forum.inductiveautomation.com/u/MikeAllgood)\
**Post date:** [March 15, 2022, 2:33pm UTC](https://forum.inductiveautomation.com/t/help-with-exception-org-python-core-pyexception-systemexit-0/57206/3 "2022-03-15T14:33:34Z")

</div>

Looks like you hit the nail on the head!  
I’m not terribly familiar with this code as another developer wrote it.  
There is a try/except block in the switchMicrometerProgram() function. The last line of the except section contains the line:

```auto
sys.exit(0)

```

Looking at the Python doc for this function, it seems this “exits from Python” and raises the exception.  
I’m not an application developer, just an old electrical engineer pretending to be a software guy!  
It doesn’t seem like this is hurting anything, but, is this the proper way to raise an exception in a script in Ignition?

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [March 15, 2022, 2:38pm UTC](https://forum.inductiveautomation.com/t/help-with-exception-org-python-core-pyexception-systemexit-0/57206/4 "2022-03-15T14:38:05Z")

</div>

Usually when I see someone trying to `exit()` it’s because they’re being lazy about control flow or can’t figure out another way to return early from the function they’re writing.

There’s probably a better way.

---

<div class="post-metadata">

**Author:** ![MikeAllgood](https://avatars.discourse-cdn.com/v4/letter/m/a183cd/32.png) [@MikeAllgood](https://forum.inductiveautomation.com/u/MikeAllgood)\
**Post date:** [March 15, 2022, 2:39pm UTC](https://forum.inductiveautomation.com/t/help-with-exception-org-python-core-pyexception-systemexit-0/57206/5 "2022-03-15T14:39:59Z")

</div>

Thanks Kevin,  
I’ll look into a change for this when time allows.  
For now, unless it starts causing issues, we’ll leave it as is and I’ll also talk with the my fellow developer to see if he wants to revisit it as well.  
👍

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [March 15, 2022, 2:40pm UTC](https://forum.inductiveautomation.com/t/help-with-exception-org-python-core-pyexception-systemexit-0/57206/6 "2022-03-15T14:40:24Z")

</div>

If the function doesn’t return anything then you can simply replace it with `return`.
