Error Found an interactive session. You cannot have multiple interactive sessions open simultaneously. To terminate the existing session, use 'delete(gc​p('nocreat​e'))'

10 views (last 30 days)
Hello everybody,
I want to create a pool but Matlab returns that I have a pool opened. I make sure that if a pool is open close it before open the new one. I mean:
delete(gcp('nocreate')); %delete the current pool
poolobj = gcp;
if isempty(poolobj)
poolsize = 1;
else
poolsize = poolobj.NumWorkers;
end
parpool(poolsize,'IdleTimeout',Inf);
This is my code. I check if a pool is opened and then open a new one.
What is wrong? It always shows that issue.
Thanks!
Javi

Accepted Answer

Javier Naranjo
Javier Naranjo on 7 Nov 2017
I am going to answer my own question if this helps to someone else.
It is not possible to open a pool with gcp and the open again with parpool.
That was the problem

More Answers (1)

Hernan
Hernan on 14 Oct 2022
Edited: Hernan on 14 Oct 2022
Hello Javier,
I arrived here looking for something else, but I think maybe what you wanted to do is something like this:
poolobj = gcp('nocreate'); % get the pool object, and do it avoiding creating a new one.
if isempty(poolobj) % check if there is not a pool.
poolsize = 1;
else
poolsize = poolobj.NumWorkers;
delete( gcp('nocreate')); % delete the current pool object.
end
parpool( poolsize, 'IdleTimeout',Inf); % create a new pool with the previous poolsize and new specs.
In that way your code works.
And what I was looking for was just to delete in case the current number of workers is different that the amount of workers that I want.
So, to replace a parpool( workers, 'IdleTimeout', idletimeout) at the begining of my code, that would drop the error here in subject, I defined the following function:
function [ poolobj ] = check_my_parpool( workers, idletimeout)
if nargin < 1
workers = 4; % default number of workers that I want.
end
if nargin < 2
idletimeout = 20; % default time in minutes of being idle before shut itself down.
end
poolobj = gcp('nocreate'); % get the pool object.
if ~isempty(poolobj) % check if there IS actually a pool:
if poolobj.NumWorkers ~= workers % it has a different number of workers???:
delete( poolobj); % delete the current pool object.
end
end
if isempty( gcp('nocreate')) % finally, if there is not a pool:
poolobj = parpool( workers, 'IdleTimeout', idletimeout); % create a new pool.
end
end
So, as example, add that function to your workspace, and then just replace:
parpool( 4);
with:
check_my_parpool( 4);
I hope this helps you,
Best,
Hernán.

Categories

Find more on Parallel Computing Fundamentals in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!