Skip to content

Instantly share code, notes, and snippets.

Avatar
💭
OSS break

Kyle Stanley aeros

💭
OSS break
  • Python Software Foundation
  • FL, US
  • Twitter @aeros_py
View GitHub Profile
View ppe_deadlock.py
"""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
View show_shutdown_executor_futures.py
"""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 Nov 14, 2019
Get the size of an object.
View get_size.py
import sys
import types
import gc
ignored_types = (
type,
types.FunctionType,
types.LambdaType,
types.MethodType,
types.BuiltinFunctionType,
@aeros
aeros / threadpool.py
Last active Nov 4, 2019
asyncio.ThreadPool prototype implementation and demo
View threadpool.py
# 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 Oct 17, 2019
Benchmark to compare the performance of asyncio.get_running_loop() and asyncio.get_event_loop() within a coroutine.
View asyncio_get_loop_bench.py
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 Nov 14, 2019
Construction time benchmark for frozenmap (immutables.Map)
View frozenmap_construction_bench.py
"""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