Python thread for pre-importing modules

前端 未结 4 1592
抹茶落季
抹茶落季 2021-01-13 21:17

I am writing a Python application in the field of scientific computing. Currently, when the user works with the GUI and starts a new physics simulation, the interpreter imme

4条回答
  •  北荒
    北荒 (楼主)
    2021-01-13 22:15

    Why not just do this when the app starts?

    def background_imports():
        import Traits
        import Mayavi
    
    thread = threading.Thread(target=background_imports)
    thread.setDaemon(True)
    thread.start()
    

提交回复
热议问题