This repository was archived by the owner on Feb 26, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +8
-4
lines changed
Expand file tree Collapse file tree 2 files changed +8
-4
lines changed Original file line number Diff line number Diff line change @@ -123,7 +123,8 @@ def eaAlphaMuPlusLambdaCheckpoint(
123123
124124 if continue_cp :
125125 # A file name has been given, then load the data from the file
126- cp = pickle .load (open (cp_filename , "rb" ))
126+ with open (cp_filename , "rb" ) as f :
127+ cp = pickle .load (f )
127128 population = cp ["population" ]
128129 parents = cp ["parents" ]
129130 start_gen = cp ["generation" ]
@@ -185,7 +186,8 @@ def eaAlphaMuPlusLambdaCheckpoint(
185186 logbook = logbook ,
186187 rndstate = random .getstate (),
187188 param_names = param_names )
188- pickle .dump (cp , open (cp_filename_tmp , "wb" ))
189+ with open (cp_filename_tmp , "wb" ) as f :
190+ pickle .dump (cp , f )
189191 if os .path .isfile (cp_filename_tmp ):
190192 shutil .copy (cp_filename_tmp , cp_filename )
191193 logger .debug ('Wrote checkpoint to %s' , cp_filename )
Original file line number Diff line number Diff line change @@ -265,7 +265,8 @@ def run(
265265 if continue_cp :
266266
267267 # A file name has been given, then load the data from the file
268- cp = pickle .load (open (cp_filename , "rb" ))
268+ with open (cp_filename , "rb" ) as f :
269+ cp = pickle .load (f )
269270 gen = cp ["generation" ]
270271 self .hof = cp ["halloffame" ]
271272 logbook = cp ["logbook" ]
@@ -361,7 +362,8 @@ def run(
361362 CMA_es = CMA_es ,
362363 param_names = param_names ,
363364 )
364- pickle .dump (cp , open (cp_filename_tmp , "wb" ))
365+ with open (cp_filename_tmp , "wb" ) as f :
366+ pickle .dump (cp , f )
365367 if os .path .isfile (cp_filename_tmp ):
366368 shutil .copy (cp_filename_tmp , cp_filename )
367369 logger .debug ("Wrote checkpoint to %s" , cp_filename )
You can’t perform that action at this time.
0 commit comments