golang报错: all goroutines are asleep
来源:互联网 发布:github ssh项目源码 编辑:程序博客网 时间:2024/06/16 20:27
在测试go channel时出现如下错误提示:fatal error: all goroutines are asleep - deadlock!
出错信息的意思是在main goroutine线中,期待从其他goroutine线放入数据,但是其他goroutine线都已经执行完了(all goroutines are asleep),那么就永远不会有数据放入管道。
所以,main goroutine线在等一个永远不会来的数据,那整个程序就永远等下去了。 这个时候就会报上述错误。验证:
package mainimport ( "fmt")func main() { ch1 := make (chan int) for { select { case <-ch1: { fmt.Println("ch1 pop one") } } }}
运行提示错误:
fatal error: all goroutines are asleep - deadlock!
在上面代码中加一个goroutine并sleep,代码会等待该gorutine结束后再打印该错误。
package mainimport ( "fmt" "time")func main() { ch1 := make (chan int) go func() { fmt.Println("sleep 1") time.Sleep(5 * time.Second) fmt.Println("sleep 2") }() for { select { case <-ch1: { fmt.Println("ch1 pop one") } } }}
打印结果:
sleep 1sleep 2fatal error: all goroutines are asleep - deadlock!
0 0
- golang报错: all goroutines are asleep
- golang fatal error: all goroutines are asleep - deadlock!
- Golang--Goroutines
- Hadoop datanode 无法启动,报错:java.io.IOException: All specified directories are failed to load.
- 关于YumRepo Error: All mirror URLs are not using ftp......报错的解决方法
- vpn报错:OpenVPN for Win32 "All TAP-Win32 adapters on this system are currently in use"
- Hive union all报错
- golang.org/x/net/websocket 报错
- How to Wait for All Goroutines to Finish Executing Before Continuing
- document.all.WebBrowser.ExecWB 报错问题
- ORA-ALL Oracle连接报错
- 编译报错 :*** [all-local] Error 2
- Not All Carrots Are Orange
- 水浒:All Men Are Brothers
- You Are All Excellent 1785
- We Are All Confident Idiots
- You Are All Excellent 排序
- hdu1785 You Are All Excellent
- Sapera LT 的配置
- 图书购买系统之实体类
- [More Effective C++]尽量使用C++风格的类型转换
- 【LeetCode】24. Swap Nodes in Pairs C语言
- 堆的介绍与应用
- golang报错: all goroutines are asleep
- 【Java之网络编程】3.UDP
- [BFS]199. Binary Tree Right Side View
- rt带宽限制浅析
- 多线程学习笔记
- 关于安卓动态加载的一点学习曲折
- 禁止iOS自动识别手机号
- SSL P2640 2016东莞市特长生考试 子数整数
- 最小费用最大流