【问题标题】:Perform an action while sleeping [duplicate]在睡觉时执行一个动作[重复]
【发布时间】:2013-04-29 14:31:41
【问题描述】:

在 python 中,是否可以像time.sleep() 一样在脚本休眠时运行代码或执行操作?我想要做的是打印一条消息并仅在打印消息后 10 秒才从用户那里收集输入。我最初虽然我可以做

print "You have ten seconds to answer the question."
print "The question"
time.sleep(10) and input() simultaneously
print "You are out of time"

这可能吗?如果没有,有什么方法可以完成同样的事情吗?

【问题讨论】:

标签: python input thread-sleep


【解决方案1】:

在睡觉的时候你什么也做不了。查找 Unix/Linux 上的 alarm(2) 系统调用是否会在一段时间后被中断。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-11-03
    • 2011-09-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-10-19
    • 1970-01-01
    相关资源
    最近更新 更多