Unregister function from eager context.
| 345 | |
| 346 | |
| 347 | class _EagerDefinedFunctionDeleter(object): |
| 348 | """Unregister function from eager context.""" |
| 349 | |
| 350 | def __init__(self, name): |
| 351 | self.name = name |
| 352 | |
| 353 | def __del__(self): |
| 354 | try: |
| 355 | context.remove_function(self.name) |
| 356 | except TypeError: |
| 357 | # Suppress some exceptions, mainly for the case when we're running on |
| 358 | # module deletion. Things that can go wrong include the context module |
| 359 | # already being unloaded, self._handle._handle_data no longer being |
| 360 | # valid, and so on. Printing warnings in these cases is silly |
| 361 | # (exceptions raised from __del__ are printed as warnings to stderr). |
| 362 | pass # 'NoneType' object is not callable when the handle has been |
| 363 | # partially unloaded. |
| 364 | except AttributeError: |
| 365 | pass # 'NoneType' object has no attribute 'eager_mode' when context has |
| 366 | # been unloaded. Will catch other module unloads as well. |
| 367 | |
| 368 | |
| 369 | # TODO(apassos) get rid of this by splitting framework.function._DefinedFunction |