wolfcrypt Python: work around minor issue in Random.__del__

During interpreter shutdown, depending on the order in which things happen, a module can be unloaded before all instances of classes defined in that module are garbage collected.

In particular, this means that any global variables (including imported modules) become `None` by the time the instances `__del__` is called, resulting in
```
AttributeError: 'NoneType' object has no attribute 'wc_FreeRng'
```
being displayed while the process exits.  This can be avoided simply by catching and ignoring the `AttributeError` in this case, since the process is shutting down anyways.
This commit is contained in:
Erik Bray
2017-02-02 16:51:41 +01:00
committed by GitHub
parent 895bf8dfbc
commit bf12e4ecca

View File

@@ -39,7 +39,11 @@ class Random(object):
def __del__(self):
if self.native_object:
try:
_lib.wc_FreeRng(self.native_object)
except AttributeError:
# Can occur during interpreter shutdown
pass
def byte(self):