APScheduler + requests 遇到 OSError: [Errno 24] Too many open files 的問題

前陣子試著在 Python 上面定時跑 crawler 抓一些東西寫進資料庫。 因為是偏實驗性質,選擇用 PyPy (PyPy3) 而非 CPython (就是官方版本的 Python),然後搭著 Gunicorn (跑 Flask) + APScheduler + requests,專案的程式碼可以在 app/app.

Gea-Suan Lin's BLOG

Ciekawostki o Pythonowym "limited API" i "stable ABI".

1. #CPython ma "limited API". Jak się tego używa, to kompilowane rozszerzenia są zgodne ze wskazaną wersją i wersjami nowszymi. Takie rozszerzenia dostają sufiks `.abi3.so` (albo podobny) zamiast np. `.cpython-313-x86_64-linux-gnu.so`.

2. Wsparcie podzielone jest między CPythona i systemy budowania #PEP517. Np. w #setuptools podaje się `py_limited_api=`, i wówczas przy budowaniu dodawane są odpowiednie flagi kompilatora i podmieniany jest sufiks rozszerzeń. #Meson ma coś podobnego.

3. Ale wersja "freethreading" aktualnie nie obsługuje "stable ABI", więc przy budowaniu z "limited API" dostaje się błąd kompilacji. Podobnie, setuptools rzuca błąd jeżeli z interpreterem freethreading podamy `py_limited_api`, a Meson po prostu pozwala się wysypać kompilacji. Tak więc autorzy paczek muszą sami sprawdzać, czy użyto kompilatora "freethreading", i wyłączyć wówczas "limited API".

4. Bliżej nieokreślona przyszła wersja CPythona naprawi to wsparcie. Nie przyglądałem się tematowi dokładnie, ale podejrzewam, że będzie to tylko możliwe, jeżeli będziemy budować rozszerzenia dla tej bądź nowszej wersji. Więc ludzie pewnie będą musieli budować dwie wersje — tę dla starszych CPythonów, i dla nowszych + "freethreading". No i oczywiście będzie trzeba odpowiednio zaktualizować warunkowe załączanie "limited API".

5. No i jest jeszcze #PyPy. PyPy nie ma "stable ABI", ale pozwala budować rozszerzenia z "limited API". Setuptools i Meson po prostu wykrywają, że interpreter nie obsługuje sufiksu `.abi3.so`, i buduje rozszerzenia z normalnym sufiksem.

#Python

Some fun facts about #Python limited API / stable ABI.

1. #CPython supports "limited API". When you use it, you get extensions that are compatible with the specified CPython version and versions newer than that. To indicate this compatibility, such extensions use `.abi3.so` suffix (or equivalent) rather than the usual `.cpython-313-x86_64-linux-gnu.so` or alike.

2. The actual support is split between CPython itself and #PEP517 build systems. For example, if you use #setuptools and specify `py_limited_api=` argument to the extension, setuptools will pass appropriate C compiler flags and swap extension suffix. There's a similar support in #meson, and probably other build systems.

3. Except that CPython freethreading builds don't support stable ABI right now, so building with "limited API" triggers an explicit error from the headers. Setuptools have opted for building explicit about this: it emits an error if you try to use `py_limited_api` on a freethreading interpreter. Meson currently just gives the compile error. This implies that package authors need to actively special-case freethreading builds and enable "limited API" conditionally.

4. A some future versions of CPython will support "limited API" in freethreading builds. I haven't been following the discussions closely, but I suspect that it will only be possible when you target that version or newer. So I guess people will need to be building two stable ABI wheels for a time — one targeting older Python versions, and one targeting newer versions plus freethreading. On top of that, all these projects will need to update their "no 'limited API' on freethreading" conditions.

5. And then there's #PyPy. PyPy does not feature a stable ABI, but it allows you to build extensions using "limited API". So setuptools and meson just detect that there is no `.abi3.so` on PyPy, and use regular suffix for the extensions built with "limited API".

🌗 RPython GC 的分配速度有多快?
➤ 深入分析 RPython 垃圾回收器的分配效率
https://pypy.org/posts/2025/06/rpython-gc-allocation-speed.html
本文探討了 RPython 垃圾回收器 (GC) 的分配速度。作者透過一個簡單的基準測試程式,測量了在 64 位元架構上分配包含單一整數欄位的物件的效能。測試結果顯示,RPython GC 在沒有初始化欄位的情況下,可以以高達 34.35 GB/s 的速度分配物件,即使初始化欄位,也能達到 29.7 GB/s。作者將 RPython GC 的效能與 Boehm GC 進行比較,並使用 perf 工具分析了快取命中率、指令週期和分支等指標。研究發現,RPython GC 的分配速度非常快,且垃圾回收佔總執行時間的比例相對較小。
+ 這篇文章對於瞭解 RPython 垃圾回收器的效能非常有幫助,提供了詳細的測試數據和分析結果。
+ 我一直很好奇 PyPy 的效能,這篇文章讓我對 RPython
#程式設計 #垃圾回收 #PyPy #RPython #效能分析
How fast can the RPython GC allocate?

While working on a paper about allocation profiling in VMProf I got curious about how quickly the RPython GC can allocate an object. I wrote a small RPython benchmark program to get an idea of the ord

PyPy

W oczekiwaniu jutrzejszej Wielkiej Zmiany, przebudowuję mój kontener roboczy #Gentoo, wyłączając wsparcie Pythona 3.10 oraz #PyPy 3.10. 1158 paczek do przebudowania — i długa lista konfliktów. Tyle że nie wiem, czy te konflikty to "nie przebuduję tych paczek", czy tylko "poradziłem sobie z nimi".

#Python

In anticipation of tomorrow's Big Switch, I'm rebuilding my #Gentoo dev conainer with #Python 3.10 and #PyPy 3.10 disabled. 1158 rebuilds — and a long list of conflicts, though I'm not sure if these conflicts were "I won't rebuild these packages" or "I have resolved them".

Do you maintain or contribute to a #Python package that includes a C extension? Would you like to run a fuzzer against it?

If so, let me know and I will run it, or help you to get it running.

The fuzzer is #fusil, which generates random code calling into your functions and methods. It's useful to check for crashes on invalid inputs or unexpected call patterns.

It has found about 50 crashes in #CPython, 20 in #PyPy, 6 in #Numpy etc.

#fuzzing #fuzzer #testing
See here:
https://github.com/devdanzin/fusil/issues/37

Fuzz C extensions · Issue #37 · devdanzin/fusil

fusil can find crashes in external C extensions. This issue records which have been fuzzed, results, and a list of possible candidates. Asking maintainers of each package beforehand whether there i...

GitHub

Przypomnienie: 2025-05-01, #Gentoo przechodzi na Pythona 3.13, jako domyślną wersję.

Usuwamy również wsparcie budowania paczek dla Pythona 3.10 i #PyPy 3.10. W odróżnieniu od wcześniejszych migracji, przejście na PyPy 3.11 wymaga zmiany flag PYTHON_TARGETS.

Spodziewamy się również, że wersja beta CPythona 3.14 wyjdzie jakoś w połowie maja, i od tego momentu będziemy stopniowo dodawać wsparcie do paczek, w miarę dostępnego czasu.

https://public-inbox.gentoo.org/gentoo-dev/d43d6cbdadfd8c6c08e976b0a627c9ddd3c616c2.camel@gentoo.org/T/#u
https://www.gentoo.org/support/news-items/2025-03-24-python3-13.html

#Python

[gentoo-dev] [Python] The big plans for May: Python 3.13 by default, Python 3.10 + PyPy 3.10 gone, Python 3.14 incoming

PSA: reminder that on 2025-05-01, #Gentoo is switching the default to #Python 3.13.

We are also removing the support for Python 3.10 and #PyPy 3.10 targets. Unlike the previous times, the upgrade to PyPy 3.11 now requires switching target flags.

We also do expect CPython 3.14 betas to land mid-May, and we will start adding relevant targets soon afterwards, as time permits.

https://public-inbox.gentoo.org/gentoo-dev/d43d6cbdadfd8c6c08e976b0a627c9ddd3c616c2.camel@gentoo.org/T/#u
https://www.gentoo.org/support/news-items/2025-03-24-python3-13.html

[gentoo-dev] [Python] The big plans for May: Python 3.13 by default, Python 3.10 + PyPy 3.10 gone, Python 3.14 incoming

Vanishing Blinds, by PYPY

from the album Sacred Times

PYPY