__init__.py 文件源码

python
阅读 24 收藏 0 点赞 0 评论 0

项目:NeoAnalysis 作者: neoanalysis 项目源码 文件源码
def exit():
    """
    Causes python to exit without garbage-collecting any objects, and thus avoids
    calling object destructor methods. This is a sledgehammer workaround for 
    a variety of bugs in PyQt and Pyside that cause crashes on exit.

    This function does the following in an attempt to 'safely' terminate
    the process:

    * Invoke atexit callbacks
    * Close all open file handles
    * os._exit()

    Note: there is some potential for causing damage with this function if you
    are using objects that _require_ their destructors to be called (for example,
    to properly terminate log files, disconnect from devices, etc). Situations
    like this are probably quite rare, but use at your own risk.
    """

    ## first disable our own cleanup function; won't be needing it.
    setConfigOptions(exitCleanup=False)

    ## invoke atexit callbacks
    atexit._run_exitfuncs()

    ## close file handles
    if sys.platform == 'darwin':
        for fd in range(3, 4096):
            if fd not in [7]:  # trying to close 7 produces an illegal instruction on the Mac.
                os.close(fd)
    else:
        os.closerange(3, 4096) ## just guessing on the maximum descriptor count..

    os._exit(0)



## Convenience functions for command-line use
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号