Skip to content

Instantly share code, notes, and snippets.

View aeros's full-sized avatar

Kyle Stanley aeros

  • Python Software Foundation
  • FL, US
  • X @aeros_py
View GitHub Profile
"""Warning: executor.shutdown(wait=False) causes deadlocks for instances of
concurrent.futures.ProcessPoolExecutor.
Not intended for usage outside of debugging and demonstration purposes.
Tested on Python 3.7.6 and 3.8.1.
"""
import concurrent.futures as cf
import time
"""Requires
https://github.com/aeros/cpython/tree/bpo39349-add-cancel_futures-to-Executor.shutdown.
See https://github.com/python/cpython/pull/18057 for details.
"""
import concurrent.futures as cf
import time
def wait_return(duration, result):
@aeros
aeros / get_size.py
Last active November 14, 2019 08:37
Get the size of an object.
import sys
import types
import gc
ignored_types = (
type,
types.FunctionType,
types.LambdaType,
types.MethodType,
types.BuiltinFunctionType,
@aeros
aeros / threadpool.py
Last active November 4, 2019 12:10
asyncio.ThreadPool prototype implementation and demo
# Authored by: Kyle Stanley (https://github.com/aeros)
import asyncio
import concurrent.futures
import threading
import functools
import weakref
import os
# Only needed for demo.
@aeros
aeros / asyncio_get_loop_bench.py
Last active October 17, 2019 07:44
Benchmark to compare the performance of asyncio.get_running_loop() and asyncio.get_event_loop() within a coroutine.
import asyncio
import time
total_tests = 10_000_000
async def test_get_running_loop():
return asyncio.get_running_loop()
async def test_get_event_loop():
return asyncio.get_event_loop()
@aeros
aeros / frozenmap_construction_bench.py
Last active November 14, 2019 08:36
Construction time benchmark for frozenmap (immutables.Map)
"""Created for the purpose of comparing the construction time
between ``dict``, ``ChainMap``, and the proposed ``frozenmap`` in PEP-603.
"""
import sys
import time
import collections
import immutables