When I interrupt a script in the middle of a parfor, some files are still opened by Matlab (e.g. I cannot delete them). I usually call flcose('all') to close all open files but it doesn't seem work in this case. What should I do?
Asked
Active
Viewed 265 times
3
user3658425
- 139
- 7
-
2Since the interrupt signal is an exception (I think), you could catch it with a `try...except` block and use the onCleanup object: http://stackoverflow.com/questions/1098149/how-do-you-handle-resources-in-matlab-in-an-exception-safe-manner-like-try – darthbith Jun 15 '14 at 17:12
1 Answers
2
That's because the parfor creates a bunch of Matlab slaves who have their own file handles. The two main solutions are:
parfor i=1:12 % 12 or some number over your number of workers
fclose('all')
end
or simply closing the parallel pool either using matlabpool close or the GUI (bottom left):
Note that you can use Process Explorer to find what process is holding a file open in Windows:
Franck Dernoncourt
- 69,497
- 68
- 312
- 474
-
Note that you can also do `pctRunOnAll fclose all` instead of the `parfor` loop. – David Kelley Dec 21 '16 at 15:21