偏偏給我碰到Python C API的Bug?Py_Initialze()直接死迴圈

來源:互聯網
上載者:User

 今天在一個程式中,在不同的兩個函數,先用Py_Initialize()初始化,然後用Py_Finalize()結束,在本機都調試沒有問題,然後將DLL發給同事後,老是在Py_Initialize()進入死迴圈,莫名其妙!怎麼調試都沒有用,奇怪了,然後將前一次的Py_Finalize()和後一次Py_Initialize()的取消,也就是僅僅經過一次的Py_Initialize(),Py_Finalize()就完全沒有問題。

這點也很奇怪,畢竟本機調試是沒有任何問題的,在同事那裡雖然換成了多線程環境,但是也沒有道理總是必在Py_Initialize()死掉吧?看了Python的文檔,才發現Py_Finalize()函數後有這麼一段

 

Bugs and caveats: The destruction of modules and objects in
modules is done in random order; this may cause destructors (__del__() methods) to fail when they depend on other objects
(even functions) or modules. Dynamically loaded extension modules loaded by
Python are not unloaded. Small amounts of memory allocated by the Python
interpreter may not be freed (if you find a leak, please report it). Memory tied
up in circular references between objects is not freed. Some memory allocated by
extension modules may not be freed. Some extensions may not work properly if
their initialization routine is called more than once; this can happen if an
application calls Py_Initialize() and Py_Finalize() more than once.

 

難道是這個問題?我這裡也不是extensions不工作的問題啊。。。。。。。或者還是多線程的問題?莫名奇妙啊。。。。。。

 

這裡順便記個關於Python在對線程環境下工作的文章,明天去好好研究一下是什麼問題。

C++調用PythonAPI線程狀態和全域解譯器鎖

http://blog.csdn.net/marising/archive/2008/10/08/3032278.aspx

 


聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.