Skip to content

Commit d03c5e0

Browse files
committed
fix: remove network-related packages from preimport warmup
chardet, charset_normalizer, requests, and httpx crash the guest with SIGSEGV during pyhl setup warmup (likely due to urllib3/ssl/anyio init). Keep them in the rootfs as shipped-but-not-preimported. Retain python-docx and python-pptx in the preimport list. Signed-off-by: danbugs <danilochiarlone@gmail.com>
1 parent 600c776 commit d03c5e0

3 files changed

Lines changed: 19 additions & 23 deletions

File tree

docs/python-packages.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,8 @@ These packages are imported during `pyhl setup` warmup. They are already in `sys
3838
| Package | Import name |
3939
|---------|-------------|
4040
| beautifulsoup4 | `bs4` |
41-
| chardet | `chardet` |
42-
| charset-normalizer | `charset_normalizer` |
4341
| click | `click` |
4442
| cryptography | `cryptography` |
45-
| httpx | `httpx` |
4643
| Jinja2 | `jinja2` |
4744
| lxml | `lxml` |
4845
| markdown-it-py | `markdown_it` |
@@ -57,7 +54,6 @@ These packages are imported during `pyhl setup` warmup. They are already in `sys
5754
| python-dotenv | `dotenv` |
5855
| python-pptx | `pptx` |
5956
| PyYAML | `yaml` |
60-
| requests | `requests` |
6157
| tabulate | `tabulate` |
6258
| tenacity | `tenacity` |
6359
| tqdm | `tqdm` |
@@ -76,6 +72,8 @@ These packages are in the rootfs but not pre-imported. The first `import` pays t
7672
| boto3 | `boto3` |
7773
| builtwith | `builtwith` |
7874
| celery | `celery` |
75+
| chardet | `chardet` |
76+
| charset-normalizer | `charset_normalizer` |
7977
| coverage | `coverage` |
8078
| distro | `distro` |
8179
| docx2txt | `docx2txt` |
@@ -91,6 +89,7 @@ These packages are in the rootfs but not pre-imported. The first `import` pays t
9189
| gitpython | `git` |
9290
| google-api-python-client | `googleapiclient` |
9391
| hypercorn | `hypercorn` |
92+
| httpx | `httpx` |
9493
| hypothesis | `hypothesis` |
9594
| loguru | `loguru` |
9695
| markdown | `markdown` |
@@ -124,6 +123,7 @@ These packages are in the rootfs but not pre-imported. The first `import` pays t
124123
| rapidfuzz | `rapidfuzz` |
125124
| rarfile | `rarfile` |
126125
| reportlab | `reportlab` |
126+
| requests | `requests` |
127127
| rope | `rope` |
128128
| ruff | `ruff` |
129129
| schedule | `schedule` |

examples/python-agent-driver/hl_pydriver.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -253,8 +253,7 @@ static void py_initialize_once(void)
253253
" 'bs4', 'tabulate', 'click', 'tenacity', 'tqdm',"
254254
" 'openpyxl', 'pypdf', 'markdown_it', 'PIL', 'lxml',"
255255
" 'cryptography', 'dateutil', 'dotenv',"
256-
" 'docx', 'pptx', 'chardet', 'charset_normalizer',"
257-
" 'requests', 'httpx'):\n"
256+
" 'docx', 'pptx'):\n"
258257
" try:\n"
259258
" importlib.import_module(_mod)\n"
260259
" except Exception as _e:\n"

host/src/bin/pyhl.rs

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,6 @@ const PREIMPORTED_MODULES: &[&str] = &[
9191
"dotenv",
9292
"docx",
9393
"pptx",
94-
"chardet",
95-
"charset_normalizer",
96-
"requests",
97-
"httpx",
9894
];
9995

10096
/// Build the long-about blurb shown by `pyhl --help`. Lists the
@@ -122,19 +118,20 @@ fn long_about() -> String {
122118
"\n\n\
123119
Additional packages shipped in the rootfs (pay import cost on \
124120
first use): aiohttp, altair, APScheduler, bandit, bokeh, \
125-
boto3, builtwith, celery, coverage, distro, docx2txt, duckdb, \
126-
edgartools, exchange-calendars, fabric, Faker, fastapi, \
127-
feedparser, fpdf2, gensim, gitpython, \
128-
google-api-python-client, hypercorn, hypothesis, loguru, \
129-
markdown, markdownify, mutagen, networkx, nltk, \
130-
numpy-financial, odfpy, paramiko, pdfplumber, pdfrw, pexpect, \
131-
pipdeptree, platformdirs, plotly, polars, praw, pycountry, \
132-
pydub, pyflakes, pygments, pylint, PyPDF2, pytest, \
133-
pytest-asyncio, pytest-cov, pyxlsb, qrcode, radon, rapidfuzz, \
134-
rarfile, reportlab, rope, ruff, schedule, scikit-learn, scipy, \
135-
scrapy, send2trash, slack-sdk, srt, statsmodels, svgwrite, \
136-
sympy, textblob, trafilatura, tweepy, typer, uvicorn, vulture, \
137-
watchdog, websockets, wordcloud, xlrd, xlsxwriter.\n\n\
121+
boto3, builtwith, celery, chardet, charset-normalizer, \
122+
coverage, distro, docx2txt, duckdb, edgartools, \
123+
exchange-calendars, fabric, Faker, fastapi, feedparser, \
124+
fpdf2, gensim, gitpython, google-api-python-client, \
125+
hypercorn, httpx, hypothesis, loguru, markdown, markdownify, \
126+
mutagen, networkx, nltk, numpy-financial, odfpy, paramiko, \
127+
pdfplumber, pdfrw, pexpect, pipdeptree, platformdirs, plotly, \
128+
polars, praw, pycountry, pydub, pyflakes, pygments, pylint, \
129+
PyPDF2, pytest, pytest-asyncio, pytest-cov, pyxlsb, qrcode, \
130+
radon, rapidfuzz, rarfile, reportlab, requests, rope, ruff, \
131+
schedule, scikit-learn, scipy, scrapy, send2trash, slack-sdk, \
132+
srt, statsmodels, svgwrite, sympy, textblob, trafilatura, \
133+
tweepy, typer, uvicorn, vulture, watchdog, websockets, \
134+
wordcloud, xlrd, xlsxwriter.\n\n\
138135
Packages not in the rootfs will raise ModuleNotFoundError.",
139136
);
140137
s

0 commit comments

Comments
 (0)