Go打印cmd.Process.Pid报错
目录
问题
今天使用Golang打印进程PID,程序居然崩了,报错信息如下:
2020/11/27 16:21:15 http: panic serving [::1]:57413: runtime error: invalid memory address or nil pointer dereference
goroutine 72 [running]:
net/http.(*conn).serve.func1(0xc0017228c0)
/usr/local/Cellar/go/1.15.4/libexec/src/net/http/server.go:1801 +0x147
panic(0x450f460, 0x48ee120)
/usr/local/Cellar/go/1.15.4/libexec/src/runtime/panic.go:975 +0x47a
github.com/Monibuca/plugin-record.(*Encoder).SaveVideo(0xc0000100c0, 0x45c77d5, 0x40, 0xc000024ae0, 0x11, 0x45b16dd, 0x15, 0x0, 0x0, 0x0, ...)
/Users/lz/job/ms/boliving/plugins/plugin-record/ffmpeg.go:260 +0x187
github.com/Monibuca/plugin-record.SaveMp4(0xc00138e7b0, 0x4, 0x0, 0x0, 0x0, 0x0, 0x0)
/Users/lz/job/ms/boliving/plugins/plugin-record/mp4.go:54 +0x30d
github.com/Monibuca/plugin-record.run.func2(0x4650580, 0xc0004b00e0, 0xc001cba100)
/Users/lz/job/ms/boliving/plugins/plugin-record/main.go:92 +0xa2d
net/http.HandlerFunc.ServeHTTP(0x45d2200, 0x4650580, 0xc0004b00e0, 0xc001cba100)
/usr/local/Cellar/go/1.15.4/libexec/src/net/http/server.go:2042 +0x44
net/http.(*ServeMux).ServeHTTP(0x48fd700, 0x4650580, 0xc0004b00e0, 0xc001cba100)
/usr/local/Cellar/go/1.15.4/libexec/src/net/http/server.go:2417 +0x1ad
net/http.serverHandler.ServeHTTP(0xc0004b0000, 0x4650580, 0xc0004b00e0, 0xc001cba100)
/usr/local/Cellar/go/1.15.4/libexec/src/net/http/server.go:2843 +0xa3
net/http.(*conn).serve(0xc0017228c0, 0x4651b00, 0xc0014220c0)
/usr/local/Cellar/go/1.15.4/libexec/src/net/http/server.go:1925 +0x8ad
created by net/http.(*Server).Serve
/usr/local/Cellar/go/1.15.4/libexec/src/net/http/server.go:2969 +0x36c
解决
代码单元测试也是通过的,为什么集成到系统里就崩溃了呢?
后来尝试了很多别的方法,最后通过单独启用一个新协程方法就解决了。至今不明白为啥,但是解决方法有了。
先记录一下,方便以后回顾思考。
文章来源: liuzhen.blog.csdn.net,作者:Data-Mining,版权归原作者所有,如需转载,请联系作者。
原文链接:liuzhen.blog.csdn.net/article/details/110235742
- 点赞
- 收藏
- 关注作者
评论(0)