Skip to content

Instantly share code, notes, and snippets.

View kumaraditya303's full-sized avatar
💭
I may be slow to respond.

Kumar Aditya kumaraditya303

💭
I may be slow to respond.
  • Earth
View GitHub Profile

asyncio

async generator's finalization is broken

import asyncio
work_done = False

async def cursor():
 try:
@kumaraditya303
kumaraditya303 / toml_data.py
Created May 25, 2022 09:54
Generate toml data for benchmarks
from urllib.request import urlopen
import json
import toml
BASE_URL = "https://api.github.com/repos/python/cpython/pulls?per_page=1000&state=all"
def main():
page = 1
all_issues = []
while page <= 10:
with urlopen(f"{BASE_URL}&page={page}") as response:
@kumaraditya303
kumaraditya303 / main.py
Last active April 27, 2025 20:34
MultiThreaded Playwright with ThreadPoolExecutor
import threading
from playwright.sync_api import sync_playwright
from concurrent.futures import ThreadPoolExecutor, ProcessPoolExecutor
class Tls(threading.local):
def __init__(self) -> None:
self.playwright = sync_playwright().start()
print("Create playwright instance in Thread", threading.current_thread().name)
@kumaraditya303
kumaraditya303 / main.py
Created February 14, 2021 15:49
Run Async function as blocking function without running it in main thread
import asyncio
from threading import Thread, enumerate
def async_to_sync() -> asyncio.AbstractEventLoop:
loop = asyncio.new_event_loop()
Thread(target=loop.run_forever).start()
return loop