Python IOError: [Errno 5] Input/output error?
Asked Answered
I

3

25

I m running on a remote server a python script using nohup.

  • First I connected to the remote machine using a VPN and SSH
  • Second I run a python script using the following command:

    nohup python backmap.py mpirun -np 48 &

The python script contains the following lines:

frame = []
file_in = open("Traj_equil_prot.pdb", "r")
for line in file_in:
    if line.startswith('TITLE'):
        frame.append(line[127:134])

import os
for fileNum in range(631, 29969):
    os.system("./initram-v5.sh -f Traj_equil_prot_frame" +  str(fileNum) + ".pdb -o Traj_equilprot_aa_frame" + str(frame[fileNum]) + ".gro -to amber -p topol.top")

The script was running just fine the whole day. but now it just crashed and when I try to re-launch it again I'm getting the following error:

Traceback (most recent call last): File "", line 1, in IOError: [Errno 5] Input/output error

The file is in the working directory. I tried to disconnect/connect again but still the same problem. I don't know what I'm missing. Any help, please?

Instar answered 17/9, 2018 at 23:31 Comment(2)
I'm not sure if related, but you have never closed file_inLeisaleiser
I just tried to open the file in python and close it with file_in.close(). Disconnect and reconnect to the remote machine and run the script again but I'm still getting the same error :/Instar
K
33

I had the same problem, I used to run my script using this command:

python MY_SCRIPT.py &

The script will run in the background and the output will be displayed on the terminal until you logout or exit.

By logging out, the script is still running but it's output has nowhere to display thus, exceptions will be made when the script wants to display something (e.g. calling print).


Solution:

I've piped the output to somewhere other than the actual terminal display:

python MY_SCRIPT.py >/dev/null &

Checkout this link for more details:

https://mcmap.net/q/539290/-python-prevent-ioerror-errno-5-input-output-error-when-running-without-stdout

Kano answered 25/9, 2018 at 22:8 Comment(2)
or I think you could use nohup. nohup python myscript.py &Toulouse
Interestingly enough, when I used print, the exception occurred but when I used sys.stdout.write, no exception was raised.Pigeon
I
0

I finally fixed the problem by opening the file "file_in", modifying it (just adding a point in the REMARK line for example) and saving the changes.

Instar answered 18/9, 2018 at 0:8 Comment(0)
T
0

I had this error trying to load some files or to copy them using shutil library. It has been solve launching my code with an output file for the buffer:

python my_code.py >> output.txt

The tqdm will still be visible, making the advancement of the code easy to fallow.

Taxation answered 21/8, 2023 at 15:25 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.