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,不过倒是没提具体是怎么实现的,估计还得去挖源码,就不深究了。

  • 相关阅读:
    PHP 统计数据功能 有感
    一个高效的工作方式
    Navicat for mysql 导出sql文件 导入sql文件
    chrome浏览器,调试详解,调试js、调试php、调试ajax
    网络编程中几个地址结构与转换(in_addr,sockaddr,sockaddr_in,pcap_addr)
    TCP 协议
    tcp抓包 Wireshark 使用
    (转)linux中常用的头文件
    ubuntu安装使用kdevelop
    安卓u8800刷机
  • 原文地址:https://www.cnblogs.com/chaoswong/p/3064527.html
Copyright © 2011-2022 走看看