Difference in the operation of script console and event script Perspective where does it come from?

Hello I have a question about the difference in the operation of script console and event script.

I have a Python script that implements the creation of screenshots from CCTV cameras. I trigger it using:

import subprocess

pythonPath = "C:/Program Files/Python/python.exe"
scriptPath = "C:/Program Files/Inductive Automation/Ignition/Script/test.py"

result = subprocess.check_output([pythonPath, scriptPath])

I have several different versions of how this works. I use the main-production gateway and two local ones for developers to test. The scenarios described below are:

  1. There is a script running on all gateways, which is triggered via script console. The code runs using python and executes all its required functions.

  2. On the production gateway I need it to execute depending on the event such as pressing a button. Unfortunately this does not work causing an error:

Error running action 'dom.onClick' on Cameras/Cameras_test Backup@D/root/Button_0: Traceback (most recent call last): File "function:runAction", line 7, in runAction File "C:\Program Files\Inductive Automation\Ignition\user-lib\pylib\subprocess.py", line 553, in check_output raise CalledProcessError(retcode, cmd, output=output) subprocess.CalledProcessError: Command '['C:/Program Files/Python/python.exe', 'C:/Program Files/Inductive Automation/Ignition/Script/test.py']' returned non-zero exit status 1

  1. On one Gateway local it also does not work as described for production gateway.

  2. On the other local gateway this script works both for script console and for perspective button trigger.

  3. To confirm the ability to execute a Python script by event on the production gateway I prepared another simple script that only executes a text to text file which works perfectly everywhere.

From what I noticed the script for taking screenshots executes a considerable amount of time i.e. about 20s can this affect the execution in perspective - event script? What could be the reasons for this behavior? What can I compare to find the cause on one local gateway it works great but I don't see any difference. I also verified gateway access to any folders and permissions what works and is confirmed by another example code that executes a smaller scope in the form of writing to a file.

Has anyone had more experience with scripting in python?

Regards,
Michal