search

Home  >  Q&A  >  body text

python中单例在什么情景下使用?

我知道在频繁使用一个类时可以使用单例模式,但在python web开发中具体什么场景呢

巴扎黑巴扎黑2889 days ago383

reply all(2)I'll reply

  • 巴扎黑

    巴扎黑2017-04-17 17:54:39

    Single cases are generally used in situations like connections. The scenario where I used singletons in python web before was that the python web service needed to connect to another service and needed to register and log in. At this time, if a singleton was not used, every client would send a request to that server through the web program. The service registers and logs in. After using the singleton, all clients only register and log in once with another service through the web, and then use this connection repeatedly until the connection expires.

    reply
    0
  • PHP中文网

    PHP中文网2017-04-17 17:54:39

    Logging is a singleton

    reply
    0
  • Cancelreply