Skip to content

Instantly share code, notes, and snippets.

View easysugar's full-sized avatar
🇺🇦
#StandWithUkraine

easy sugar easysugar

🇺🇦
#StandWithUkraine
View GitHub Profile
@easysugar
easysugar / set_startup.py
Created February 17, 2020 14:44
Script for create startup python code
import site
path = site.getusersitepackages() + '/sitecustomize.py'
command = '''
from settings.py import *
'''
with open(path, 'w') as f:
f.write(command)
@easysugar
easysugar / async_pipeline.py
Created July 29, 2020 09:00
simple constructor for using async functions like pipelines
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
@easysugar
easysugar / async_mutliprocessing.py
Last active August 5, 2020 11:15
Using async functions in mutliprocessing
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))
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