I am running a script on a school computer using the multiprocessing module. I am serializing the data frequently. It can be summarized by the code below:
import multiprocessing as mp
import time, pickle
def simulation(j):
data = []
for k in range(10):
data.append(k)
time.sleep(1)
file = open('data%d.pkl'%j, 'wb')
pickle.dump(data, file)
file.close()
if __name__ == '__main__':
processes = []
processes.append(mp.Process(target = simulation, args = (1,) ))
processes.append(mp.Process(target = simulation, args = (2,) ))
for process in processes:
process.start()
for process in processes:
process.join()
So when I actually run my code for many more simulations and what I imagine to be more intensive varied tasks, I get the following error: IOError: [Errno 5] Input/output error usually preceded by file.open(...) or file.close().
My questions:
- How do I fix this error in my script?
- What does this error mean for a python newcomer? References appreciated.
Some more notes about my procedure:
- Instead of setting the multiprocess attribute
daemonto beTrue, I use screen to run the script and then detach. This allows me also to disconnect without worrying about my script stopping. - This seemed to be a related question about printing using the
subprocessmodule. I did not explicitly use daemon as I said, so not sure if this will help. - This usually happens after running for about a day and occurs on different processes at different times.
nohupinstead ofscreento decrease the number of 'layers' between me and the kernel. He said roughly speaking this might increase the chances that this error doesn't crop up. Anyways, it still does...