dlr-gtlab / python-module

GTlab Module for embadding Python into GTlab
0 stars 0 forks source link

Python Task with subprocess stdout/stderr redirect produces error #277

Open rainman110 opened 9 months ago

rainman110 commented 9 months ago

In GitLab by @schu_m27 on Feb 2, 2024, 14:16

This code in a GtpyTask gives an error:

import sys
import subprocess

LogFile = sys.stdout
ErrFile = sys.stdout

p = subprocess.Popen("ls", stdout=LogFile, stderr=ErrFile)

Error traceback:

File "/opt/sgsoftware/miniforge3/envs/py39/lib/python3.9/subprocess.py", line 829, in __init__
  errread, errwrite) = self._get_handles(stdin, stdout, stderr)
File "/opt/sgsoftware/miniforge3/envs/py39/lib/python3.9/subprocess.py", line 1598, in _get_handles
  c2pwrite = stdout.fileno()
rainman110 commented 9 months ago

In GitLab by @schu_m27 on Feb 2, 2024, 14:17

I had a similar problem once after reassignent the sys.stdout to an own object and missed to implement methods from TextIOWrapper, e.g.

    def fileno(self):
        """
        To be compatible to sys.stdout and sys.stderr
        """
        return self._fileno

See https://gitlab.dlr.de/pyconvutius/pycotoolbox/-/blob/main/pycotoolbox/threadsysoutredirect.py?ref_type=heads

rainman110 commented 6 months ago

In GitLab by @jensschmeink on May 8, 2024, 07:27

moved from gtlab/gtlab-issuetracking#90