使用TCL超时
TCL 有没有办法将一段代码包含在超时块中?我的意思是,即使执行未完成,该块也会在特定超时后退出。 例如:-
timeout (interval) {
#wait for socket connection here
}
如果在间隔时间内没有建立连接,则块退出。
谢谢和问候, 安贾利
Is there a way in TCL to enclose a piece of code in a timeout block? What I mean by that is that the block will exit after a particular timeout even if the execution is not complete.
For instance:-
timeout (interval) {
#wait for socket connection here
}
If no connection is established in interval time, the block exits.
Thanks and Regards,
Anjali
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
安贾利,
您正在寻找
vwait
。这是一个示例:等待五秒钟以连接到服务器套接字,否则关闭套接字并继续运行脚本:
编辑
您需要使用 非阻塞 I/O< 与 UART 设备进行通信/a>.
Anjali,
You are looking for
vwait
.Here is an example: Wait five seconds for a connection to a server socket, otherwise close the socket and continue running the script:
Edit
You will need to communicate with your UART device using non blocking I/O.
我知道这是一个老问题,每隔几年我都会被同样的问题绊倒。我想提供 vwait 的替代方案,因为实际上没有必要,尽管有一些重要的警告尚未指出。这是专门针对串行 i/o 期间的超时,如原始问题所示。这是摘录。我知道完整的代码更好,但无论如何,所有 I/O 对于您的设备来说都是唯一的。
I know this is an old question, every few years I keep tripping over the same issues. I want to offer an alternative to
vwait
because, in fact, it is not necessary, though there are a couple of important caveats which have not been pointed out. This is specifically targeting timeouts during serial i/o, as in the original question. It's an excerpt. I know complete code is preferable, but all i/o will be unique to your device, anyway.