So I am currently working remotely and trying to have a Python script run on an Ubuntu machine while not maintaining the ssh connection to it. The usual solution is a detached screen that allows to let the script run while breaking the connection pipe.
However, my script calls another program (LTspice) which happens to run only on Windows but was installed on the Ubuntu machine using Wine.
I am using the subprocess library in python to perform this call. (wine LTspice.exe)
Although the script works perfectly when ssh-connected, as soon as the pipe is broken, the script fails to process for an unknown reason, but as soon as I reconnect and reattach, the script works again. The issue might come from different aspects as it involves ssh, screen, wine, python subprocess and LTspice but i am trying to investigate and solve this issue. (I am from a physics background so please cope with my shallow knowledge on those aspects, I want to learn).
In order to have a simple test on the issue that is a part of my main script, I created this small other test script:
Test.py:
from subprocess import call
import subprocess
import os
import sys
import config2 as config # a config file that includes the paths in a Linux format
file_path = config.tmp_asc_file[:-4]
spice_exe_path = config.LTSpice_executable_path
pathC='C:/'+file_path.split('/',5)[-1] #this adapt the path to windows format that LTspice reads
#inside the wine environment
while True:
command="wine "+ spice_exe_path+' -wine -netlist "'+ pathC+ '.asc"'
print(repr(command))
#call(["bash","-c",command])
#subprocess.run(['wine',spice_exe_path,'-wine','-netlist',pathC+'.asc' ],check=True)
subprocess.run(['bash','-c', command],check=True)
command='wine '+ spice_exe_path+' -wine -b'+' -ascii "'+ pathC+'.net"'
print(repr(command))
#call(["bash","-c",command])
#subprocess.run(['wine',spice_exe_path,'-wine','-b','-ascii',pathC+'.net' ],check=True)
subprocess.run(['bash','-c', command],check=True)
try:
os.remove(file_path+'.net')
except:
print("file does not exist")
try:
os.remove(file_path+'.log')
except:
print("file does not exist")
try:
os.remove(file_path+'.op.raw')
except:
print("file does not exist")
try:
os.remove(file_path+'.raw')
except:
print("file does not exist")
This script was created following my understanding of the advice found in Running Bash commands in Python. I just run this (python test.py) in a linux screen. Files are processed by LTspice and the output files created can thus be removed. Detaching and re attaching does not make the script fail. But detaching, breaking the ssh connection (simple exit after detaching) then connecting again to the remote machine and re attaching shows the "file does not exist" prints in previous output lines while most recent shows the script is working again.
Could this issue be due to screen and subprocess interaction? Or a wine/screen? Or maybe just LTspice issues working with wine? I am eager for any feedback on methods to investigate and test the cause(s) of my issue, or bypass it as long as the solution allows me to not stay connected to the remote machine.
Thanks in advance.