-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3d5e924
commit ec5e726
Showing
3 changed files
with
33 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import asyncio | ||
|
||
|
||
async def gather(*coros_or_futures): | ||
queue = asyncio.Queue() | ||
|
||
async def task(coro_or_future): | ||
result = await coro_or_future | ||
await queue.put(result) | ||
|
||
tasks = [task(c) for c in coros_or_futures] | ||
task_sum = asyncio.gather(*tasks) | ||
for _ in range(len(tasks)): | ||
yield await queue.get() | ||
await task_sum | ||
|
||
if __name__ == "__main__": | ||
import random | ||
|
||
async def main(): | ||
async def wait(n): | ||
await asyncio.sleep(n) | ||
return n | ||
tasks = [wait(n) for n in range(10)] | ||
random.shuffle(tasks) | ||
async for n in gather(*tasks): | ||
print(n) | ||
|
||
asyncio.run(main()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,7 +17,7 @@ | |
|
||
setup( | ||
name='dblp_crawler', | ||
version='2.0.1', | ||
version='2.1', | ||
author='yindaheng98', | ||
author_email='[email protected]', | ||
url='https://github.com/yindaheng98/dblp-crawler', | ||
|