Invoke Python Method Keeps Running Even After Excel Forecast is Saved

Hi everyone,

I’m currently running a Python script from UiPath using the Invoke Python Method activity. The script uses Prophet to forecast top 5 sender IDs based on Excel data, and it successfully creates and saves the result to a local Excel file.

:white_check_mark: The output file is saved correctly, so the script works.
:cross_mark: But in UiPath, the process never ends — it just keeps “running” after calling the Python method, without error and without moving forward to the next activity.

Here’s what I’ve tried:

  • Using Load Python ScriptInvoke Python Method
  • The Python function returns "done" at the end
  • No input() or plot.show() is used
  • The script runs fine in VSCode/terminal
  • No exceptions are thrown

my code :
import pandas as pd
from prophet import Prophet
import warnings
warnings.filterwarnings(“ignore”)

def forecast_top5_senderid_june_2025(excel_path):
df = pd.read_excel(excel_path, sheet_name=“CleanedData”)
df[“tanggal”] = pd.to_datetime(df[“tanggal”])
df = df[(df[“tanggal”] >= “2025-01-01”) & (df[“tanggal”] <= “2025-05-31”)]

results = []

for sid in df["sender_id"].unique():
    sid_df = df[df["sender_id"] == sid].copy()
    ts_df = sid_df.groupby("tanggal")["total_transaksi"].sum().reset_index()
    ts_df.columns = ["ds", "y"]

    if len(ts_df) < 15:
        continue

    try:
        model = Prophet()
        model.fit(ts_df)

        future = model.make_future_dataframe(periods=30, freq='D')
        forecast = model.predict(future)

        june_forecast = forecast[(forecast["ds"].dt.month == 6) & (forecast["ds"].dt.year == 2025)]
        total_june = june_forecast["yhat"].sum()

        results.append((sid, total_june))
    except Exception:
        continue

result_df = pd.DataFrame(results, columns=["sender_id", "total_forecast_june_2025"])
top5 = result_df.sort_values(by="total_forecast_june_2025", ascending=False).head(5)
top5["total_forecast_june_2025"] = top5["total_forecast_june_2025"].round().astype(int)

# Output file is created correctly
save_path = r"your\output\path\here\hasil_forecast_june_2025.xlsx"
top5.to_excel(save_path, index=False)

return "done"

Has anyone faced this kind of issue where Invoke Python Method never completes even though the script itself has finished and the output file is already created?

Would really appreciate any help or insight :folded_hands:
Thanks in advance!

Hi @nashwasabila11
As per my understanding,try to add os._exit(0) at the end of the python function. this forcefully terminates the python process after the task is done, ensuring UiPath can continue.
Or alternatively, use start process or run python script instead of invoke python method to execute the script externally.

If you found helpful please mark as a solution. Thanks
Happy Automation with UiPath

1 Like

@nashwasabila11

  1. First check if you see any error messages in event viewer logs
  2. Try to include log messages and write the logs to a text file or so ..to verify where it is getting stuck

Generally when stuck you would see an error in event viewer based on that we can see the nect steps

Cheers

hi, thankyou for help

1 Like

hello, thankyou so much!

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.