未验证 提交 a722940a 编写于 作者: D daquexian 提交者: GitHub

fix exception in BlobObject __del__ (#3742)

* fix exception in BlobObject __del__

* address comments
Co-authored-by: Noneflow-bot <69100618+oneflow-bot@users.noreply.github.com>
上级 c736c538
......@@ -59,9 +59,11 @@ import oneflow.python_gen.__export_symbols__
import atexit
import oneflow.python.framework.c_api_util
import oneflow.python.framework.python_interpreter_util
atexit.register(oneflow.python.framework.c_api_util.DestroyEnv)
atexit.register(oneflow.python.framework.session_context.TryCloseDefaultSession)
atexit.register(oneflow.python.framework.python_interpreter_util.SetShuttingDown)
del atexit
del absolute_import
......
......@@ -15,6 +15,7 @@ limitations under the License.
"""
from __future__ import absolute_import
import oneflow.python.framework.python_interpreter_util as python_interpreter_util
import oneflow.python.eager.symbol as symbol_util
import oneflow
......@@ -53,7 +54,11 @@ class BlobObject(Object):
def add_releaser(self, release):
self.release_.append(release)
def __del__(self):
# Bind `python_interpreter_util.IsShuttingDown` early.
# See the comments of `python_interpreter_util.IsShuttingDown`
def __del__(self, is_shutting_down=python_interpreter_util.IsShuttingDown):
if is_shutting_down():
return
for release in self.release_:
release(self)
self.release_ = []
"""
Copyright 2020 The OneFlow Authors. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
"""
"""
It's copied from
https://github.com/numba/llvmlite/blob/3701287/llvmlite/binding/common.py
"""
import atexit
# module globals may be cleared at shutdown,
# so declare this variable as an array to avoid "global _shutting_down"
_shutting_down = [False]
def SetShuttingDown():
_shutting_down[0] = True
def IsShuttingDown(_shutting_down=_shutting_down):
"""
Whether the interpreter is currently shutting down.
For use in finalizers, __del__ methods, and similar; it is advised
to early bind this function rather than look it up when calling it,
since at shutdown module globals may be cleared.
"""
return _shutting_down[0]
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册