zoukankan      html  css  js  c++  java
  • bottle坑爹的reload

    这两天用bottle在写一个小应用,里面我开了一个线程,专门监听远程一台服务器。那台服务器对重复连接作了处理,会断开之前的旧连接,结果当我运行下面的代码时,总是提示重连:

    import threading
    t = threading.Timer(2, long_connect)
    t.start()
    
    from bottle import run
    run(app,host='localhost',port=8000,reloader=True)

    其中long_connect是我用于监听那台服务器的函数,那里一直会提示我:远程连接已断开,开始重连。

    这事折腾了我好几天,今天偶然看了一下任务管理器,发现执行上面的代码会启动两个python进程,这是啥原因,google了半天没发现有用的信息,难道别人都没遇到过。

    自己翻文档吧,然后看到这么一段:

    Auto Reloading
    During development, you have to restart the server a lot to test your recent changes. The auto reloader can do this for you. Every time you edit a module file, the reloader restarts the server process and loads the newest version of your code.

    from bottle import run
    run(reloader=True)

    How it works: the main process will not start a server, but spawn a new child process using the same command line arguments used to start the main process. All module-level code is executed at least twice! Be careful.

    不知道各位看到我标红的那段是什么感受,反正我是快崩溃了。

    你妈,打开reloader所有的代码会执行两次啊!!

    哎,以后一定要小心这些参数,真心坑爹啊。

    PS:flask听说跟bottle类似,所以又去看了看它的文档,用的是user_reloader,不过倒是没提具体是怎么实现的,估计还得去挖源码,就不深究了。

  • 相关阅读:
    Hibernate4究竟怎么玩目录
    Hibernate检索策略之5.2多对一单向关联检索策略——Hibernate4究竟怎么玩
    Struts2 OGNL表达式中调用java静态方法无效的解决办法
    JDBC API中的execute返回值问题
    Hibernate检索策略之5.1类级别检索策略——Hibernate4究竟怎么玩
    PowerDesigner逆向工程mysql
    三种批量增加的性能分析
    Apache FtpServer的使用
    杭电1013
    杭电1008
  • 原文地址:https://www.cnblogs.com/chaoswong/p/3064527.html
Copyright © 2011-2022 走看看