helpers.py 文件源码

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

项目:qudi 作者: Ulm-IQO 项目源码 文件源码
def exit(exitcode=0):
    """
    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.

    @param int exitcode: system exit code
    """

    if has_pyqtgraph:
        # first disable our pyqtgraph's cleanup function; won't be needing it.
        pyqtgraph.setConfigOptions(exitCleanup=False)

    # invoke atexit callbacks
    atexit._run_exitfuncs()

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

    os._exit(exitcode)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号