Possible Duplicate:
How do you handle resources in MATLAB in an exception safe manner? (like “try … finally”)
I use Matlab parallel computing toolbox this way:
matlabpool open
parfor …
matlabpool close
If error occurs in parfor, the program is terminated, and matlabpool is not closed. When I fix the bug and run it again, matlabpool open fails because it is already open. So I need to close it manually, which I always forget. The ideal way would be to change it to (pseudo-code):
matlabpool open
try
parfor …
finally
matlabpool close
end
Is there any best practice for this?