@@ -42,11 +42,15 @@ def __init__(self, original_name):
42
42
A instance of an axelrod Game
43
43
"""
44
44
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
45
49
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 )
47
51
self .shared_library = load_library (self .shared_library_filename )
48
- self .__original_name = original_name
49
52
self .original_function = self .original_name
53
+
50
54
is_stochastic = characteristics [self .original_name ]['stochastic' ]
51
55
if is_stochastic is not None :
52
56
self .classifier ['stochastic' ] = is_stochastic
@@ -62,11 +66,11 @@ def original_name(self):
62
66
return self .__original_name
63
67
64
68
@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
68
72
else :
69
- raise ValueError ('{} is not a valid Fortran function' .format (value ))
73
+ raise ValueError ('{} is not a valid Fortran function' .format (key ))
70
74
71
75
@property
72
76
def original_function (self ):
@@ -118,7 +122,16 @@ def _release_shared_library(self):
118
122
# thread closes before the player class is garbage collected, which
119
123
# tends to happen at the end of a script.
120
124
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 )
122
135
except FileNotFoundError :
123
136
pass
124
137
0 commit comments