描述
如果工作流步骤在执行过程中出错,则会发生 WorkflowExecutionStepError 异常。
讨论
如果工作流步骤无法执行,则会发生 WorkflowExecutionStepError 异常。例如,如果试图执行不支持的步骤,如 DefineAOI、EditExtendedProperties, LaunchArcMap、LaunchGP, OpenMap 和 SelectDataWorkspace,则会产生错误。
代码示例
在下面的异常处理方法中,WorkflowExecutionStepError 异常用于处理试图执行工作流中的步骤时产生的所有错误。
import arcpy
import sys
import traceback
# Define the callback response function. In this case it will prompt the user using the console to respond.
def callback(question, responses):
# Print out the expected responses
for resp in responses:
print("[%i] %s" + (resp[1], resp[0]))
# Prompt the user to respond
val = int(input("%s - %s: " % (question[1], question[0])))
# Return their response. Currently only returning the value, but could also return a note (for questions) and the name of the response
return val, "", ""
# Establish a connection to a Workflow database
conn = arcpy.wmx.Connect(r'c:\test\Workflow.jtc')
# Get a Job for Execution
job = conn.getJob(77601)
try:
# Execute the current Step in the Job - a LaunchArcmap step without Proceed to Next enabled
result = job.executeStep(callback=callback)
# A Launch ArcMap step will not finish automatically it will be complete after the user indicates it is.
if not result.finished:
t = input("Please press any key and hit enter when finished step")
# Finish the step and Mark as Complete
result.finishStep(callback=callback)
job.markStepAsComplete(callback=callback)
# Run the next step in the workflow
result = job.executeStep(callback=callback)
print("Executing a 2nd step returned %i" % result.returnCode)
# Mark the step as complete
job.markStepAsComplete(callback=callback)
except wmx.WorkflowExecutionStepError as e:
print("Step failed to execute:")
print("-"*60)
traceback.print_exc()