import time
from threading import Thread
import asyncio
class bankcrawl_model():
def __init__(self):
self.status="sleeping"
def login(self):
self.status="logging"
print("this is status:","logging")
time.sleep(3)
def getinfo(self):
self.status="getinfo"
print("this is status:","getinfo")
time.sleep(3)
def crawl(self):
print("this is status:","crawl")
self.status="crawl"
time.sleep(3)
self.status="sleeping"
print("this is status:","None")
class ModelThread(Thread):
def __init__(self,model):
Thread.__init__(self)
self.model=model
def run(self):
self.model.login()
self.model.getinfo()
self.model.crawl()
async def get_status(model):
old = model.status
print(old)
while True:
new=model.status
if new!=old:
old=new
print(new)
if new=="sleeping":
break
if __name__=='__main__':
print("main start!")
model=bankcrawl_model()
modellist=[model]
start_thread(modellist)
loop=asyncio.get_event_loop()
loop.run_until_complete(get_status(model))
print("main end")
结合线程与异步实时获取爬虫爬取状态status
最新推荐文章于 2024-08-24 10:07:52 发布