# Exiting a Python script

**URL:** https://forum.highend3d.com/t/exiting-a-python-script/11070
**Category:** Archived
**Tags:** nuke
**Created:** [April 29, 2015, 1:54pm UTC](https://forum.highend3d.com/t/exiting-a-python-script/11070 "2015-04-29T13:54:02Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![user\_deleted](https://forum.highend3d.com/letter_avatar_proxy/v4/letter/u/35a633/32.png) [@user\_deleted](https://forum.highend3d.com/u/user_deleted)
#### Post date: [April 29, 2015, 1:54pm UTC](https://forum.highend3d.com/t/exiting-a-python-script/11070/1 "2015-04-29T13:54:03Z")

</div>

I am writing a script that a user triggers by selecting an item in a menu. &nbsp;First, the script must check if any nodes are selected, so I wrote this code:

selectedNodes = nuke.selectedNodes()

if len(selectedNodes) == 0:  
&nbsp; &nbsp; msg = 'No nodes selected.'&nbsp; &nbsp; &nbsp;&nbsp;  
&nbsp; &nbsp; nuke.message(msg)

If no nodes were selected, the script should flash a message and exit after the user clicks the 'OK' button. &nbsp;I am trying to figure out how to do this. &nbsp;According to the docs, nuke.scriptExit() exits Nuke, which I do not want. &nbsp;I tried using nuke.scriptClose(), which caused Nuke to exit and realaunch! &nbsp;I then used sys.exit(), which caused Nuke to exit. &nbsp;Any hints?&nbsp;
