擅长:python、mysql、java
<p>你需要在while循环外启动计时器。还有几种方法可以实现计时器,但这应该是可行的(我简化了它,您需要根据业务逻辑调整它)</p>
<pre><code>import time
start_time = datetime.now()
max_time_allowed = 45
while path != "e" and path !="n":
#Business logic here
current_time= datetime.now()
if current_time-start_time > max_time_allowed:
return
</code></pre>