The Go Programming Language
› http://golang.org/
› Go Playground
Go Projects
› Revel Web Framework
thefack

在终端中运行 golang 程序,滚动终端的输出时有可能导致线程卡死??

  •  
  •   thefack · Aug 9, 2020 · 4166 views
    This topic created in 2305 days ago, the information mentioned may be changed or developed.

    环境是 Windows10,go1.12

    在 powershell 中运行 build 好的程序,当用鼠标滚轮滚动查看程序的输出内容时,极有可能导致进程卡住,表现为不再输出内容和网速占用降为 0kb,当按了 Ctrl+c 就恢复正常。而不滚动终端的输出时就没有发生过这种情况。

    请问大伙遇到过这种情况吗?

    10 replies  •  2020-08-09 17:38:22 +08:00
    yulon
    yulon
    Aug 9, 2020
    1
    你选中文字了吧,大概怕你白选,控制台会暂停了标准输入输出
    wwqgtxx
    wwqgtxx
    Aug 9, 2020 via iPhone❤️2
    2
    只要是控制台程序都会这样吧,当滚动终端的时候会阻塞标准输入输出,如果没有在独立线程中 print 的就会卡住当前执行 print 的线程
    thefack
    thefack
    OP
    Aug 9, 2020
    3
    @yulon
    @wwqgtxx
    明白了,谢谢
    locoz
    locoz
    Aug 9, 2020 via Android
    4
    是这样的…你还可能会碰到一个疑似 bug 的情况:控制台最小化之后,过段时间程序也卡住了
    mmdsun
    mmdsun
    Aug 9, 2020 via Android
    5
    关闭 powershell 的快速编辑模式。
    zhuzeitou
    zhuzeitou
    Aug 9, 2020 via Android❤️1
    6
    封装一个自己的 log 或者什么的,不直接 print 到 stdout 或 stderr,而是先写到一个 buffer 中,然后用一个 goroutine 负责从 buffer 读取内容 print,这样可能阻塞的 print 只会发生在这个 goroutine,调用 log 的时候不会发生阻塞
    May725
    May725
    Aug 9, 2020 via iPhone
    7
    正常的,敲一下回车键就正常了
    thefack
    thefack
    OP
    Aug 9, 2020
    8
    @locoz
    @mmdsun
    @zhuzeitou
    @May725
    谢谢大伙,原来如此,以前没注意过这种问题。
    toomlo
    toomlo
    Aug 9, 2020
    9
    哇,学习到了~~~
    mengyx
    mengyx
    Aug 9, 2020 via Android❤️1
    10
    可以用 windows terminal,可以避免这个问题
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   2257 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 44ms · UTC 13:51 · PVG 21:51 · LAX 05:51 · JFK 08:51
    ♥ Do have faith in what you're doing.