@@ -42,11 +42,15 @@ def __init__(self, original_name):
4242 A instance of an axelrod Game
4343 """
4444 super ().__init__ ()
45+ # The order of the next 4 lines is important. We must first check that
46+ # the player name is valid, then grab a copy of the shared library,
47+ # and then setup the actual strategy function.
48+ self .original_name = original_name
4549 self .index , self .shared_library_filename = \
46- shared_library_manager .get_filename_for_player (original_name )
50+ shared_library_manager .get_filename_for_player (self . original_name )
4751 self .shared_library = load_library (self .shared_library_filename )
48- self .__original_name = original_name
4952 self .original_function = self .original_name
53+
5054 is_stochastic = characteristics [self .original_name ]['stochastic' ]
5155 if is_stochastic is not None :
5256 self .classifier ['stochastic' ] = is_stochastic
@@ -62,11 +66,11 @@ def original_name(self):
6266 return self .__original_name
6367
6468 @original_name .setter
65- def original_name (self , value ):
66- if value in characteristics :
67- self .__original_name = value
69+ def original_name (self , key ):
70+ if key in characteristics :
71+ self .__original_name = key
6872 else :
69- raise ValueError ('{} is not a valid Fortran function' .format (value ))
73+ raise ValueError ('{} is not a valid Fortran function' .format (key ))
7074
7175 @property
7276 def original_function (self ):
@@ -118,7 +122,16 @@ def _release_shared_library(self):
118122 # thread closes before the player class is garbage collected, which
119123 # tends to happen at the end of a script.
120124 try :
121- shared_library_manager .release (self .original_name , self .index )
125+ name = self .original_name
126+ index = self .index
127+ except AttributeError :
128+ # If the Player does finish __init__, because the name of a
129+ # non-existent strategy is supplied, a copy of the shared library
130+ # won't be loaded, nor will self.original_name or self.index
131+ # exist. In that case there's nothing to do.
132+ return
133+ try :
134+ shared_library_manager .release (name , index )
122135 except FileNotFoundError :
123136 pass
124137
0 commit comments