Repository: xonsh/xonsh
Pull request: fix tcsetattr: Interrupted system call
try fixes #2170 

Problem statement:
script that calls ssh gets interrupted
```
laerus@xonsh$ cat autossh 
ssh laerus@192.168.1.10
laerus@xonsh$ ./autossh 
^Z <--- didn't press anything here, this comes from xonsh or ssh
```

tried again with a non-lan remote
```
laerus@xonsh$ ./autossh
^Z
tcsetattr: Interrupted system call
```

Hints from issue discussion:

Commit message: fix tcsetattr: Interrupted system call

Patch to review:
diff --git a/news/xonsh-script-fix.rst b/news/xonsh-script-fix.rst
new file mode 100644
index 0000000000..e42eeec3ed
--- /dev/null
+++ b/news/xonsh-script-fix.rst
@@ -0,0 +1,13 @@
+**Added:** None
+
+**Changed:** None
+
+**Deprecated:** None
+
+**Removed:** None
+
+**Fixed:**
+
+* Fixed a ``tcsetattr: Interrupted system call`` issue when run xonsh scripts.
+
+**Security:** None
diff --git a/xonsh/built_ins.py b/xonsh/built_ins.py
index 032e197614..e0ef5f68ad 100644
--- a/xonsh/built_ins.py
+++ b/xonsh/built_ins.py
@@ -535,6 +535,9 @@ def prep_preexec_fn(self, kwargs, pipeline_group=None):
         """Prepares the 'preexec_fn' keyword argument"""
         if not (ON_POSIX and self.cls is subprocess.Popen):
             return
+        env = builtins.__xonsh_env__
+        if not env['XONSH_INTERACTIVE']:
+            return
         if pipeline_group is None:
             xonsh_preexec_fn = no_pg_xonsh_preexec_fn
         else:


Code review comments:
diff_hunk: @@ -535,6 +535,9 @@ def prep_preexec_fn(self, kwargs, pipeline_group=None):
         """Prepares the 'preexec_fn' keyword argument"""
         if not (ON_POSIX and self.cls is subprocess.Popen):
             return
+        env = builtins.__xonsh_env__
+        if not env['XONSH_INTERACTIVE']:
path: xonsh/built_ins.py
text: @user1:
This might need to be env.get('XONSH_INTERACTIVE')

@user2:
`'XONSH_INTERACTIVE' in env`?

@author:
I think this is safe. this env is always set during the start up phase, and here is a run-sub-proc phase. But I could update a bit :)

@author:
Ok, I see the points. CI was failing because of this. In tests we may only mock part of the ENVs.