Skip to content

Instantly share code, notes, and snippets.

@pwtail
pwtail / shock.py
Created February 4, 2023 00:09
For django forum
import asyncio
import threading
import time
from asyncio import get_event_loop
from functools import wraps
from concurrent.futures import ThreadPoolExecutor
# implemented for fun. Could use asriref
def sync_to_async(f):
import asyncio
from functools import wraps
# это https://github.com/Bi-Coloured-Python-Rock-Snake/greenhack
from greenhack import exempt, as_async
def wrap_outer(co_func):
@wraps(co_func)
def wrapper(*args, **kwargs):
@pwtail
pwtail / pg_benchmark_insert.py
Last active December 2, 2022 18:44
Pg benchmark (inserting)
import asyncio
import concurrent
from concurrent.futures import ThreadPoolExecutor
from contextlib import contextmanager
import sys
import random
import time
import uvloop
asyncio.set_event_loop_policy(uvloop.EventLoopPolicy())
@pwtail
pwtail / benchmark_pg.py
Created December 2, 2022 00:56
Benchmark pg
import asyncio
import concurrent
from concurrent.futures import ThreadPoolExecutor
from contextlib import contextmanager
import sys
import random
import time
import uvloop
asyncio.set_event_loop_policy(uvloop.EventLoopPolicy())
class Super:
def __get__(self, instance, owner):
parent = super(self.owner, instance)
return getattr(parent, self.name)
def __set_name__(self, owner, name):
self.name = name