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
async def gather_dict(tasks: dict): | |
async def mark(key, coro): | |
return key, await coro | |
return { | |
key: result | |
for key, result in await gather( | |
*(mark(key, coro) for key, coro in tasks.items()) | |
) | |
} |
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
from binascii import crc32 | |
def port_number(app_name, min_port=49152, max_port=65535): | |
""" | |
Returns a port number based on the given app_name which falls in the range | |
[min_port, max_port]. | |
""" | |
checksum = crc32(app_name) & 0xffffffff | |
scale = max_port - min_port | |
return int((checksum / float(0xffffffff)) * scale + min_port) |