社区所有版块导航
Python
python开源   Django   Python   DjangoApp   pycharm  
DATA
docker   Elasticsearch  
aigc
aigc   chatgpt  
WEB开发
linux   MongoDB   Redis   DATABASE   NGINX   其他Web框架   web工具   zookeeper   tornado   NoSql   Bootstrap   js   peewee   Git   bottle   IE   MQ   Jquery  
机器学习
机器学习算法  
Python88.com
反馈   公告   社区推广  
产品
短视频  
印度
印度  
Py学习  »  Python

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

Sid • 3 年前 • 904 次点击  

我是个新手 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
 
904 次点击