Py学习  »  Python

python——如何打破异步睡眠?

Sid • 3 年前 • 842 次点击  

我是个新手 asyncio .

我如何摆脱困境 asyncio.sleep(secs) ?

def onPendingTickers(tickers):
    for t in tickers:
         print(t)

    tz = pytz.timezone('America/Mexico_City')
    if datetime.now(tz).time() >= datetime.strptime('13:30', '%H:%M').time():
        ib.disconnect()
        print('breaking')

ib.pendingTickersEvent += onPendingTickers
ib.sleep(5*60)
conn.close()
ib.pendingTickersEvent -= onPendingTickers
ib.sleep(5*60)

#is where I can't figure out how to break out of
#in case time is above particular time.

这个 sleep 功能:

def sleep(secs: float = 0.02) -> bool:
    """
    Wait for the given amount of seconds while everything still keeps
    processing in the background. Never use time.sleep().

    Args:
        secs (float): Time in seconds to wait.
    """
    run(asyncio.sleep(secs))
    return True

我该如何摆脱困境 ib.sleep() ?

我在哪里可以了解更多信息?

Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/130981
 
842 次点击