Closed JuanPabloMF closed 7 months ago
os.popen
works whilst subprocess.popen
gives read failed error. Looks like with subprocess.popen the windows shell settings are not loaded.
While not python related, ever since upgrading to WSL2 from WSL1 I randomly get these errors while typing in Windows Terminal. For instance, here I was typing ls -al
:
This is rendering my WSL terminal useless as it is happening quite often and the only solution I can find is to exit Windows Terminal and startup another one until it happens again.
Is there any sort of diagnostic information I can provide during the times in which this error occurrences which would help someone figure out its root cause? Again, this only started happening with WSL2.
Just by luck today I happened to find the root cause of the problems for me. I use gvim for Windows to edit files on the WSL filesystem. I do this via the \\wsl$
fileshare using this script:
~/bin/gvim
:
#!/bin/bash
CMNT='/c'
CMD='/c/Windows/System32/cmd.exe'
GVIM='/c/Program Files (x86)/Vim/vim81/gvim.exe'
FILE=`realpath "${1:-.}"`
if [[ $FILE == $CMNT/* ]] ;
then
FILE=${FILE/$CMNT\//C:\\}
else
# replace the first forward slash
FILE=${FILE/\//\\\\wsl\$\\Ubuntu\\}
fi
# replace the rest
FILE=${FILE//\//\\}
echo Launch gvim for file: $FILE
`"$GVIM" $FILE` &
This allows me to type: gvim myfile
and have it do the necessary conversion of the path from WSL to Windows for myfile.txt
. For instance:
$ pwd
/home/craiger/tmp
$ gvim myfile.txt
This would launch gvim for Windows in the following way:
/c/Program Files (x86)/Vim/vim81/gvim.exe \\wsl$\Ubuntu\home\craiger\tmp\myfile.txt &
If I was in a /c
folder (Windows filesystem) then it'd open C:\...\myfile.txt
instead.
So long as that instance of gvim is running, I will get read failed 5: I/O error
for each character I type in the terminal as long as gvim remains open. As soon as I close gvim, the errors go away.
Is there something I can do to maintain my ability to use gvim to open files within the WSL filesystem but get rid of the error I'm receiving in the terminal as a result?
I think what I'll do is open this as a separate ticket as I don't believe it is Python related
This issue has been automatically closed since it has not had any activity for the past year. If you're still experiencing this issue please re-file this as a new issue or feature request.
Thank you!
Environment
Steps to reproduce
I am calling
python file1.py
and getting the error "read failed 5: I/O error" multiple times.Here is the file1.py code
Basically this file opens the game and executes a few key strokes in order to open automatically a replay.
Openrep.py contains the following code:
The keys file contains the following:
Expected behavior
Calling for
python file1.py
should open the game and execute the keystrokes. This works fine if I call directly from powershell or cmd the two subprocess commands. Also it works fine if I open a python shell in WSL and manually import the module and execute the function.Actual behavior
I am repeateadly getting "read failed 5: I/O error". I did a
wsl --shutdown
which made it work for a while, but then the error started repeating.