PYTHON

Hey guys, there is a problem when I am trying to run a file in UiPath, with a python file, the file runs without problem, but a certain point of execution, the python file does not run and freezes, but when I stop the process in UiPath the python file keeps running, like magic and it completes the process, but I have to stop the process in UiPath

Do you know why this can happen?

Hi, @andros_torres_aranda

UiPath Python freezes coz it spawns a separate python.exe process that doesn’t stop with UiPath.

When you hit stop, UiPath kills its part but Python keeps chugging in background till done.

Quick fix: Kill lingering python.exe in Task Manager before run > Test script alone in cmd/PyCharm first > Use Load Python Script + Invoke Method (not direct file) > Add prints/try-catch in Python to spot hangs > Wrap in Try Catch + Terminate Workflow. Update UiPath.Python.Activities package too.

Hi @andros_torres_aranda

UiPath freezes because it launches Python as a separate python.exe process. When the script blocks or produces large output, UiPath waits forever, but python.exe continues running in the background. When you press Stop, UiPath stops but Python keeps running and finishes normally.

Fix it by using Load Script + Invoke Method, reducing returned data, add logs in Python, upgrade the Python package, and killing leftover python.exe before re-running.

If this helped you fix the problem, please mark as solution so it can help others too

Hi @andros_torres_aranda

This happens because UiPath is waiting for Python to return a response, but your Python script is still running in the background, and UiPath thinks it is “blocked”.

Try this-

Add this at the top of the script.

import sys
sys.stdout = open(sys.devnull, ‘w’)

Also, always return something from the method.

call this using:

  • Python Scope
  • Load Script
  • Invoke Python Method: main

Lastly, Do NOT use Run Python Script for long processes

Instead, wrap everything inside a function and call it with Invoke Python Method.

@andros_torres_aranda

when you say UiPath freezes does it go into not responding or its just in running?

if in running then may be python is still running and its a big script

if not responding then it might be that the cpu usage might be high with noth UiPath and python running

killing UiPath not stopping python is because of separate processes

cheers