Alteryx Designer Desktop Discussions

Find answers, ask questions, and share expertise about Alteryx Designer Desktop and Intelligence Suite.

Stop Python tool to Run

Mukeshy12390
8 - Asteroid

Hi All,

 

Is there way to stop Python Tool from running if incoming data [#1] is blank ?

 

Regards,

Mukesh Y

 

 

3 REPLIES 3
PhilipMannering
16 - Nebula
16 - Nebula

"blank" meaning zero records?

Mukeshy12390
8 - Asteroid

yes no record.

 

I will give more details, so there is Filter tool  before python tool which decide the record flow.

PhilipMannering
16 - Nebula
16 - Nebula

So, you do get an error if no records get passed to the Python Tool. One way I found to avoid the error is to use,

from ayx import Alteryx
import sys

try:
    df = Alteryx.read('#1')
except:
    sys.exit(0)

 

This will prevent any later code from running.

 

If you have tools connected downstream of the Python Tool then you get a "There is no valid metadata outgoing..." error. If this happens it might be more appropriate to use,

from ayx import Alteryx
import pandas as pd

try:
    df = Alteryx.read('#1')
except:
    md = Alteryx.readMetadata('#1')
    df = pd.DataFrame(md).iloc[:0]

Alteryx.write(df,1)

 

It's difficult to say without more details on what the Python Tool is doing. But the first option will definitely stop the Python Tool from running (at least in part) as requested.

 

Note that I'm going off the assumption that the Python Tool will be in "Production" mode. The workflow is attached.

Labels