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
import asyncio | |
futures = {} | |
def async_future_cache(func): | |
async def wrapped(*args, **kwargs): | |
if args in futures: | |
return await futures[args] | |
f = asyncio.Future() | |
futures[args] = f |
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
import asyncio | |
from concurrent.futures import ProcessPoolExecutor, as_completed | |
async def func(): | |
pass | |
def process_main(*args, **kwargs): | |
loop = asyncio.new_event_loop() | |
asyncio.set_event_loop(loop) | |
loop.run_until_complete(func(*args, **kwargs)) |
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 async_pipeline(pipe): | |
if isinstance(pipe, tuple): | |
for f in pipe: | |
await async_pipeline(f) | |
elif isinstance(pipe, set): | |
await asyncio.gather(*map(async_pipeline, pipe)) | |
else: | |
await pipe |
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
import site | |
path = site.getusersitepackages() + '/sitecustomize.py' | |
command = ''' | |
from settings.py import * | |
''' | |
with open(path, 'w') as f: | |
f.write(command) |