Skip to content

Commit

Permalink
fix:loop
Browse files Browse the repository at this point in the history
  • Loading branch information
Guovin committed Jun 15, 2024
1 parent 4c39b95 commit c4a0742
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
7 changes: 2 additions & 5 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ async def sort_channel_list(self, cate, name, info_list):
int((self.pbar.n / self.total) * 100),
)

async def process_channel(self, loop):
async def process_channel(self):
async with self.semaphore:
try:
cate, name, old_urls = await self.channel_queue.get()
Expand All @@ -116,7 +116,6 @@ async def process_channel(self, loop):
if config.open_online_search and self.results["open_online_search"]:
online_info_list = (
await async_get_channels_info_list_by_online_search(
loop,
self.results["open_online_search"],
format_name,
)
Expand Down Expand Up @@ -192,10 +191,8 @@ async def main(self):
self.tasks = []
await self.visit_page()
self.total = self.channel_queue.qsize()
loop = asyncio.get_running_loop()
self.tasks = [
asyncio.create_task(self.process_channel(loop))
for _ in range(self.total)
asyncio.create_task(self.process_channel()) for _ in range(self.total)
]
self.pbar = tqdm_asyncio(total=self.total)
self.pbar.set_description(f"Processing, {self.total} channels remaining")
Expand Down
15 changes: 10 additions & 5 deletions utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,11 +279,16 @@ def get_channels_info_list_by_online_search(pageUrl, name):
return info_list


async def async_get_channels_info_list_by_online_search(loop, pageUrl, name):
with concurrent.futures.ThreadPoolExecutor() as pool:
info_list = await loop.run_in_executor(
pool, get_channels_info_list_by_online_search, pageUrl, name
)
async def async_get_channels_info_list_by_online_search(pageUrl, name):
"""
Get the channels info list by online search
"""
# with concurrent.futures.ThreadPoolExecutor() as pool:
# loop = asyncio.geto_running_loop()
# info_list = await loop.run_in_executor(
# pool, get_channels_info_list_by_online_search, pageUrl, name
# )
info_list = get_channels_info_list_by_online_search(pageUrl, name)
return info_list


Expand Down

0 comments on commit c4a0742

Please sign in to comment.