英文:
Weird issue with running thread::sleep in a loop in kubernetes
问题
我只能在我的牧场Kubernetes云中重现这个问题。在本地运行正常。然而,如果我创建一个调用循环中的sleep的新线程,Rocket会挂起,我不知道为什么。
tokio::spawn(async move {
loop {
thread::sleep(Duration::from_secs(1));
}
});
这使得很难知道每隔x秒运行某个函数。
英文:
I am only able to reproduce this issue in my rancher kubernetes cloud. Locally it runs fine. However, if I spawn a new thread which calls sleep in a loop. Rocket will hang and I don't know why.
tokio::spawn(async move {
loop {
thread::sleep(Duration::from_secs(1));
}
});
This makes it really hard to know run some function every x seconds.
答案1
得分: 1
使用 tokio::time::sleep,如 @aleksander-krauze 在评论中所解释的那样,修复了问题。
英文:
using tokio::time::sleep instead as explained by @aleksander-krauze in the comments fixed the issue.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论