Files
Jeong, YunWon eb1546ae08 posix: add os.forkpty so pty.spawn does not hang (#8782)
* posix: add os.forkpty

pty.fork prefers forkpty so a nested spawn is a new session with its
own controlling tty. The openpty+login_tty fallback hung the
jsontests collector.

Assisted-by: Claude

* select: rebuild fd sets after EINTR

select(2) updates the sets in place. Retrying an interrupted call
with empty sets and a NULL timeout blocks forever.

Assisted-by: Claude

* http.server: keep CGI off the body-read timeout

A millisecond handler timeout races the client thread writing the
request and is inherited across CGI fork, which RSTs the client
under load.

Assisted-by: Claude

* Revert "http.server: keep CGI off the body-read timeout"

Lib edits outside a CPython copy are not allowed.

Assisted-by: Claude

* host_env: note why forkpty is libc not nix

Assisted-by: Claude

* benches: run deepcopy 10x more iterations

Assisted-by: Claude
2026-09-22 14:54:46 +09:00

73 lines
1.5 KiB
Python

# Adapted from python/pyperformance 1.14.0 (deepcopy).
"""
Benchmark to measure performance of the python builtin method copy.deepcopy
Performance is tested on a nested dictionary and a dataclass
Author: Pieter Eendebak
"""
import copy
from dataclasses import dataclass
@dataclass
class A:
string: str
lst: list
boolean: bool
def benchmark_reduce(n):
""" Benchmark where the __reduce__ functionality is used """
class C(object):
def __init__(self):
self.a = 1
self.b = 2
def __reduce__(self):
return (C, (), self.__dict__)
def __setstate__(self, state):
self.__dict__.update(state)
c = C()
for _ in range(n):
_ = copy.deepcopy(c)
def benchmark_memo(n):
""" Benchmark where the memo functionality is used """
A = [1] * 100
data = {'a': (A, A, A), 'b': [A] * 100}
for _ in range(n):
_ = copy.deepcopy(data)
def benchmark(n):
""" Benchmark on some standard data types """
a = {
'list': [1, 2, 3, 43],
't': (1 ,2, 3),
'str': 'hello',
'subdict': {'a': True}
}
dc = A('hello', [1, 2, 3], True)
for _ in range(n):
for _ in range(30):
_ = copy.deepcopy(a)
for s in ['red', 'blue', 'green']:
dc.string = s
for value in range(5):
dc.lst[0] = value
for b in [True, False]:
dc.boolean = b
_ = copy.deepcopy(dc)
N = 10
benchmark(N)
benchmark_reduce(5 * N)
benchmark_memo(N)