onCleanup and script
조회 수: 9 (최근 30일)
이전 댓글 표시
Hello.
I'm using a parfor loop,but sometimes I stop its execution with ctrl+c, so I would like to execute the command "matlabpool close" immediately in order not to leave the processes on. I have recommended to use onCleanup function,but I have read that I need to use it within a function and not in a script, and I've got a script, owe to that fact I wonder if I could do the same with a try/catch sentence, is it possible?
thanks!
댓글 수: 0
채택된 답변
Walter Roberson
2011년 7월 27일
No. try/catch cannot catch a control-c .
I would suggest just converting your script in to a function: doing so is likely to be far easier than working around the issue.
댓글 수: 4
Walter Roberson
2011년 7월 27일
The onCleanup function is invoked when the object it returns ("c" in this case) goes out of scope and is destroyed. Normally that happens when the workspace of the function is cleaned up in preparation for returning from the function, but if the object were to be returned or written in to a global or persistent variable, it might get delayed.
onCleanup runs whatever function it is handed. Note that that is _function_: you do not pass it a reference to a particular variable or object.
추가 답변 (1개)
Javier
2011년 7월 27일
댓글 수: 1
Walter Roberson
2011년 7월 27일
onCleanup() should go just after you have created the conditions that need to be cleaned up later -- e.g., just after you have opened the pool.
참고 항목
카테고리
Help Center 및 File Exchange에서 Error Handling에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!