我正在使用RubyPython
导入Python模块。我正在构造函数(RubyPython.start
)中进行initialize
,我想我应该在析构函数中对称地执行RubyPython.stop
,但不幸的是,似乎Ruby中没有析构函数:
class QDSHiveHelper
def initialize
RubyPython.start
qds = RubyPython.import('blah')
...
end
def do_something
qds.some_function
...
end
def finalize
RubyPython.stop
end
end
有人可以解释一下如何做到这一点吗? ObjectSpace.define_finalize
似乎气馁,并且有一些陷阱(不能使用封闭等)。我也可以离开RubyPython
悬挂而不是打电话给stop
,但我不知道会有什么后果。什么是最好的出路?