Advent of Code is back! Unwrap daily challenges to sharpen your Alteryx skills and earn badges along the way! Learn more now.

Alteryx Server Discussions

Find answers, ask questions, and share expertise about Alteryx Server.

Python runs in Gallery with Significant Delays compared to Designer

Peter_Guirguis
6 - Meteoroid

I have a workflow that has a python code less than 100 lines run in Designer in about 8 minutes. When running from Gallery it completes in 4hrs. Is there any reason why this is happening? and/or how to resolve it?

 

##Python code below##

 

 

from ayx import Alteryx
import pandas as pd
import os
import subprocess
from datetime import datetime, timedelta

# Read the input data from Alteryx
df = Alteryx.read("#1")
# Path to the 7-Zip executable
seven_zip_path = r'C:\Program Files\7-Zip\7z.exe'

# Path to save the batch script
batch_script_path = 'CSD-MFT BATCH FILE.bat'

# Open the batch script file for writing
with open(batch_script_path, 'w') as bat_file:
# Write the initial batch script setup
bat_file.write('@echo off\n')
bat_file.write('setlocal EnableDelayedExpansion\n\n')

for index, row in df.iterrows():
# Extract details from each row
source_file_path = row['FullPath']
file_name = row['Output File Name']
password = row['Password']
mft_folder = row['MFT Folder ']
extension = row['Extension']

# Handle different extensions
if extension == '.csv':
# Handle CSV files (no compression)
target_file_path = os.path.join(mft_folder, file_name)
bat_file.write(f'echo Copying {source_file_path} to {target_file_path}...\n')
bat_file.write(f'copy "{source_file_path}" "{target_file_path}"\n')

elif extension == '.zip':
# Handle ZIP files
target_zip_file_path = os.path.join(mft_folder, file_name.replace('.csv', '.zip'))
if pd.notna(password) and password.strip():
bat_file.write(f'echo Zipping {source_file_path} to {target_zip_file_path} with password...\n')
bat_file.write(f'"{seven_zip_path}" a -tzip -p{password} "{target_zip_file_path}" "{source_file_path}"\n')
else:
bat_file.write(f'echo Zipping {source_file_path} to {target_zip_file_path} without password...\n')
bat_file.write(f'"{seven_zip_path}" a -tzip "{target_zip_file_path}" "{source_file_path}"\n')

elif extension == '.gzip':
target_gzip_file_path = os.path.join(mft_folder, file_name.replace('.csv', '.gz'))
bat_file.write(f'echo Compressing {source_file_path} to {target_gzip_file_path} using 7-Zip...\n')
bat_file.write(f'"{seven_zip_path}" a -tgzip "{target_gzip_file_path}" "{source_file_path}"\n')

else:
print(f"Unsupported file extension: {extension}")

# Finalize the batch script
bat_file.write('\necho Processing complete.\n')
bat_file.write('pause\n')

print(f"Batch script created at {batch_script_path}")

# Execute the batch script
try:
subprocess.run([batch_script_path], check=True, shell=True)
print("Batch script executed successfully.")
except subprocess.CalledProcessError as e:
print(f"An error occurred while executing the batch script: {e}")

# Write output to Alteryx
Alteryx.write(df, 1)





2 REPLIES 2
fmvizcaino
17 - Castor
17 - Castor

Hi @Peter_Guirguis ,

 

It looks ok to me! 

 

A few things for you to do or verify

  1. Disregard this one if you are manually running the workflow on the Gallery. If the workflow is scheduled, check if the actual runtime is 4 hours or if the workflow was waiting for 4 hours to start the execution
    1. This could be caused by a congested Alteryx Server with many workflow in the queue waiting to be executed.
    2. If this is your case, you would reach out to your server admin and see the best time to schedule your workflow
    3. https://community.alteryx.com/t5/Engine-Works/Tackling-Queued-Jobs-With-Queueing-Theory-Part-1/ba-p/...
  2. Execute the workflow on the Server`s designer
    1. This is very similar to running the workflow on the Gallery. I would suggest adding timestamps in the middle of your code so you can understand where the issue is happening
    2. If the workflow runs in 8 minutes, open the Server`s designer with the run as credentials or service account user to guarantee you are reproducing the same level of permissions the Gallery has. Again, this is something your server admin will know and understand
  3. If the issue remains, it might be a network issue, meaning that your server is having a hard time accessing the input files (very common) or the server is, for some reason, preventing or delaying 7zip from working (not common)
  4. Server performance issues: Not enough memory, disk space.

 

Let me know if any of these work.

Best,

Fernando Vizcaino

Peter_Guirguis
6 - Meteoroid

Thanks Fernando, I was already testing on Server's Designer and getting the same results, I will try the timestamps idea that's very good idea