Skip to content

Instantly share code, notes, and snippets.

@davidwindell
Created September 19, 2017 14:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save davidwindell/13a09511117fdd1523b9f31c0bb23dd5 to your computer and use it in GitHub Desktop.
Save davidwindell/13a09511117fdd1523b9f31c0bb23dd5 to your computer and use it in GitHub Desktop.
#include <dlfcn.h>
#include <pthread.h>
#include <stdio.h>
// THIS IS TO AVOID A SIGFAULT WHEN RUNNING python3.6 manage.py runserver
// This should be fixed at some point by Alpine and/or Python
// Check this issue for more info
// https://github.com/docker-library/python/issues/211
typedef int (*func_t)(pthread_t *thread, const pthread_attr_t *attr, void *(*start_routine)(void*), void *arg);
int pthread_create(pthread_t *thread, const pthread_attr_t *attr, void *(*start_routine)(void*), void *arg) {
pthread_attr_t local;
int used = 0, ret;
if (!attr) {
used = 1;
pthread_attr_init(&local);
attr = &local;
}
pthread_attr_setstacksize((void*)attr, 2 * 1024 * 1024); // 2 MB
func_t orig = (func_t)dlsym(RTLD_NEXT, "pthread_create");
ret = orig(thread, attr, start_routine, arg);
if (used) {
pthread_attr_destroy(&local);
}
return ret;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment