简体   繁体   English

当我点击ctrl-c时,为什么龙卷风需要这么长时间才能死?

[英]Why does Tornado take so long to die when I hit ctrl-c?

When developing a Tornado application, I frequently want to restart the server to pick up new changes. 在开发Tornado应用程序时,我经常要重新启动服务器以获取新的更改。 I hit ctrl-c to stop the server, but with Tornado, this seems to be very slow. 我点击ctrl-c来停止服务器,但是使用Tornado,这似乎很慢。 It waits for many seconds before shutting down, or doesn't shut down at all when issued a ctrl-c. 在关闭之前等待很多秒,或者在发出ctrl-c时根本不关闭。

What's weird, is if, after clicking ctrl-c, I make a new request to the server (by, for example, refreshing my browser that is pointing at the server), it shuts down right away. 有点奇怪的是,在点击ctrl-c之后,我向服务器发出一个新请求(例如,通过刷新指向服务器的浏览器),它会立即关闭。

Anyone know how to explain this or fix it? 有谁知道如何解释或修复它? Anyone experienced something similar? 有人经历过类似的事吗

(Note, this is on Windows.) (注意,这是在Windows上。)

In Python, signals are always handled by the main thread. 在Python中,信号总是由主线程处理。 If the IOLoop is run from the main thread, it will block it when server is idle and waiting for IO. 如果从主线程运行IOLoop,它将在服务器空闲并等待IO时阻止它。 As a result, all signals will be pending on the thread to wake up. 结果,所有信号都将挂起在线程上唤醒。 That explains why sending a request shuts the server down. 这就解释了为什么发送请求会关闭服务器。

UPDATE: You can try something like this: 更新:您可以尝试这样的事情:

def set_ping(ioloop, timeout):
    ioloop.add_timeout(timeout, lambda: set_ping(ioloop, timeout))

and then: 然后:

ioloop = tornado.ioloop.IOLoop.instance()
set_ping(ioloop, timedelta(seconds=2))
ioloop.start()

when you start the loop. 当你开始循环。 As a result, select will be called with 2.0 seconds timeout, preventing the blocking. 因此,将使用2.0秒超时调用select ,以防止阻塞。 (See also IOLoop Timeouts ) (另请参阅IOLoop超时

(Note: I could not reproduce your situation on Linux, even though I manually set select to be used, so I cannot give 100% guarantee that this will help, but sounds plausible) (注意:我无法在Linux上重现你的情况,即使我手动设置select使用,所以我不能100%保证这会有所帮助,但听起来似乎有道理)

我不知道为什么用Ctrl+C退出需要这么长时间,但在某些情况下我按下Ctrl+\\ (Linux终端)

add_timeout works; add_timeout工作; if you want to save on re-registering the timeout, instead you can do this: 如果你想节省重新注册超时,你可以这样做:

ili=tornado.ioloop.IOLoop.instance()
tornado.ioloop.PeriodicCallback(lambda: None,500,ili).start()
ili.start()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在使用 Python 子进程时,为什么 Ctrl-C 不会产生与 kill -2 相同的行为? - When using Python subprocess, why does Ctrl-C not produce the same behavior as kill -2? 在Python中,为什么控制台输出有时会暂停,直到按ctrl-c为止,我该如何停止呢? - In Python, why does console output occasionally pause until ctrl-c is pressed, and how can I stop this? 为什么在向此tcp代理执行“ curl”时需要“ Ctrl-c” - Why do I need `Ctrl-c` when `curl` to the this tcp proxy 点安装spacy时按ctrl-c,现在尝试再次安装时出现错误 - Hit ctrl-c during a pip install of spacy, now getting error when attempt to install again 当字典在函数中时,为什么我的 Fibonacci 需要这么长时间? - Why does my Fibonacci take so long when the dictionary is in the function? 为什么这条线需要这么长时间才能运行? - Why does this line take so long to run? 为什么这需要这么长时间才能匹配? 这是一个错误吗? - Why does this take so long to match? Is it a bug? 为什么程序运行需要这么长时间? - Why does the program take so long to run? 为什么导入 openpyxl 需要这么长时间? - Why does importing the openpyxl take so long? ROS 中的持续时间计算和控制 - 此外,为什么即使在按下 Ctrl-C 后该脚本仍会继续运行? - Duration calculation and control in ROS - furthermore why does this script keep running even after pressing Ctrl-C?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM