I have a python script added to a toolbox in ArcGIS Pro 2.8. I need to terminate early if certain conditions are met but I need the script to complete successfully and not error. I am trying to use sys.exit(0) and it says the script run succeeded in messages. However the History pane is showing it as a Red ! as if it failed which is blocking me from publishing as a web tool. Is there a better way to exit early?
I just figured it out. I was able to just use return to move me back to def main.
""" def main(): tbx = Toolbox() tool = ExposureTool() tool.execute(tool.getParameterInfo(),None) if __name__ == '__main__': main() """
Quit() is giving me the same result as sys.Exit()
Instead of sys.exit() can you try quit() ?
import time for x in range(0,10): if x == 9: print(f'{x} Quit in 5 seconds') time.sleep(5) quit()
Not sure this will work, but have you tried wrapping the json_in process into a try/except and in the except block log the debug message and exit?
Here is that specific part as the entire code is rather large. What I am trying to do is create a tool that will be published but I do not want people seeing the syntax used for the input. So I need the tool to successfully run by using some placeholder text rather than valid json the tool would need to fully execute.
def execute(self, parameters, messages): """The source code of the tool.""" # setting up needed pieces messages = [] contact_lists = [] email_list = [] # setting up logging LOG_FILENAME = sys.path[0] + "\\logging_AmicaGP." + dt.now().strftime("%Y%m%d%H%M%S%f") + ".txt" logging.basicConfig(filename=LOG_FILENAME, format='%(asctime)s %(levelname)s %(message)s', level=10) with open(LOG_FILENAME, 'w'): pass arcpy.AddMessage("log file: " + LOG_FILENAME) logging.debug('This is a LOG file for AMICA GP tool') arcpy.Delete_management("in_memory") json_in = parameters[0].valueAsText if json_in == 'Input Feature': logging.debug('Setting up discrete input for publishing purposes') sys.exit(0)
Could you provide the code?
Les membres connectés peuvent publier, suivre les mises à jour, et plus encore. Nouveau ici ? Inscrivez-vous gratuitement.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.