Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# Changelog

## Unreleased

### macOS: give the embedded Python worker an 8 MiB stack

The asynchronous worker now uses pthread attributes to request at least 8 MiB
on macOS. The default secondary-thread stack could be exhausted while loading
native scientific packages such as NumPy. Other platforms and synchronous runs
are unchanged.

## 1.9.0

### New export: `serious_python_hard_exit(int exit_code)`
Expand Down
28 changes: 27 additions & 1 deletion src/serious_python_run.c
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,9 @@ static int sp_getenv_present(const char* k) {
#else
#include <pthread.h>
#include <unistd.h>
#if defined(__APPLE__)
#include <TargetConditionals.h>
#endif
// `used` is mainly for Darwin/Mach-O: dart_bridge is statically linked into
// the host app, and some public entry points are discovered later via dlsym
// / Dart FFI. Mark exported functions as used so the host linker's dead-strip
Expand Down Expand Up @@ -667,7 +670,30 @@ EXPORT int serious_python_run(const sp_run_config_t* cfg) {
CloseHandle((HANDLE)h);
#else
pthread_t thread;
if (pthread_create(&thread, NULL, sp_worker, st) != 0) {
#if defined(__APPLE__) && TARGET_OS_OSX
// The default macOS secondary-thread stack is too small for some Python
// native extensions (notably NumPy/OpenBLAS). Keep larger OS defaults.
pthread_attr_t attr;
if (pthread_attr_init(&attr) != 0) {
sp_state_free(st);
return -1;
}
size_t stack_size;
int attr_rc = pthread_attr_getstacksize(&attr, &stack_size);
if (attr_rc == 0 && stack_size < 8 * 1024 * 1024) {
attr_rc = pthread_attr_setstacksize(&attr, 8 * 1024 * 1024);
}
if (attr_rc != 0) {
pthread_attr_destroy(&attr);
sp_state_free(st);
return -1;
}
int create_rc = pthread_create(&thread, &attr, sp_worker, st);
pthread_attr_destroy(&attr);
#else
int create_rc = pthread_create(&thread, NULL, sp_worker, st);
#endif
if (create_rc != 0) {
sp_state_free(st);
return -1;
}
Expand Down
Loading