在和boost ::蟒蛇::导入后会发生什么? [英] What happens during and after boost::python::import?

查看:110
本文介绍了在和boost ::蟒蛇::导入后会发生什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

升压文档不指定。当我使用提振::蟒蛇::进口,正是被指定模块导入?我的猜测是在'__ __主(只是为了确保)。

The Boost documentation does not specify this. When I use boost::python::import, where exactly is the specified module imported? My guess would be in '__main__' (just to make sure).

此外,当模块对象超出范围会发生什么?鉴于Boost的文档&MDASH的措辞; 返回:对象实例持有到导入模块的引用—我猜只有参考超出范围,模块对象仍然发现在'__ __主(或者是任何一个被导入)。

Also, what happens when the module object goes out of scope? Given the wording in Boost's docs — "Returns: An instance of object which holds a reference to the imported module" — I would guess only the reference goes out of scope, the module object is still found within '__main__' (or wherever it was imported).

推荐答案

的基本机制是 PyImport_ImportModule ,并没有,它不触及 __ __主要。成功导入模块插入 sys.modules中 字典,所以当你DECREF什么函数返回的对象没有被释放 - 仍有至少是一个参考活着

The underlying mechanism is PyImport_ImportModule, and no, it doesn't touch __main__. Successfully imported modules are inserted into sys.modules dict, so the object is not freed when you DECREF what the function returns — there is still at least that one reference alive.

这篇关于在和boost ::蟒蛇::导入后会发生什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆