The following patch to Python/thread_pthread.h should fix the FreeBSD? python crashing problem discussed on #226 on freebsd, python/zope may crash repeatably when browsing diffs or saving certain pages. This fix is automatically applied if you installed Python 2.1.3 using the ports after Feb 2003. Using a recent version of the FreeBSD? ports is much better than manually trying to use these patches.
To install a new Python 2.1.3 on FreeBSD?, do the following:
- Install a recent (Python 2.1.3) FreeBSD? port collection
You can find instructions on how to install the FreeBSD? ports collection in the FreeBSD? Handbook, Chapter 4.5 Using the Ports Collection:http://www.freebsd.org/doc/en_US.ISO8859-1/books/handbook/ports-using.html
You might also want to check that the python21 port you're building is Python 2.1.3. To verify this, look at the PORTVERSION line in /usr/ports/lang/python21/Makefile. If it isn't 2.1.3, you should update your ports collection via cvsup or this page. Instructions are in the Handbook chapter I referenced above. Note that the ports collection is about 15Mb. You can also only download /usr/ports/langs/python21 (4.0 stable).
The port will automatically fetch Python 2.1.3 from the Python website
- use
make
to compile python - then kill off all running pythons (
killall -9 python
) - use
make install
to install the python 2.1.3 (system wide)
Remarks
- Note that a similar patch is applied to the FreeBSD? ports-tree later than: Thu Feb 6 11:27:49 2003.
Check if you have /usr/ports/lang/python21/files/patch-Python-thread_pthread.h-stacksize and files/zwiki.patch. Using the most recent FreeBSD? python port is always recommended. - This might also fix similar problems on AIX (zope-dev post)
- You may need to increase the <<17 to as much as <<20 or greater (1Mb) to allocate sufficient thread stack space to handle both zope and the zwiki regexps. It's based on the patch at http://collector.zope.org/Zope/560 but properly handles the case where PTHREAD_SYSTEM_SCHED_SUPPORTED is undefined.
- How to Get Python 2.1.3, FreeBSD? and Plone to Happily Coexist (same kind of article, but nicer layout ;)
If you really want to patch Python 2.1.3 by hand, use the following information
*** /usr/ports/distfiles/python/Python-2.1.3/Python/thread_pthread.h Thu Jan 10 03:12:20 2002 --- work/Python-2.1.3/Python/thread_pthread.h Thu Oct 17 21:59:48 2002 *************** *** 128,141 **** { pthread_t th; int success; - #ifdef PTHREAD_SYSTEM_SCHED_SUPPORTED pthread_attr_t attrs; ! #endif dprintf(("PyThread_start_new_thread called\n")); if (!initialized) PyThread_init_thread(); - #ifdef PTHREAD_SYSTEM_SCHED_SUPPORTED pthread_attr_init(&attrs); pthread_attr_setscope(&attrs, PTHREAD_SCOPE_SYSTEM); #endif --- 128,141 ---- { pthread_t th; int success; pthread_attr_t attrs; ! dprintf(("PyThread_start_new_thread called\n")); if (!initialized) PyThread_init_thread(); pthread_attr_init(&attrs); + pthread_attr_setstacksize (&attrs, (1<<17)); + #ifdef PTHREAD_SYSTEM_SCHED_SUPPORTED pthread_attr_setscope(&attrs, PTHREAD_SCOPE_SYSTEM); #endif *************** *** 153,163 **** func, arg #elif defined(PY_PTHREAD_STD) - #ifdef PTHREAD_SYSTEM_SCHED_SUPPORTED &attrs, - #else - (pthread_attr_t*)NULL, - #endif (void* (*)(void *))func, (void *)arg #endif --- 153,159 ----
To manually apply this patch
- make sure you've got a recent FreeBSD? ports files (see above)
cd /usr/ports/lang/python21
make extract
- Apply the patch to
work/Python-2.1.3/Python/thread_pthread.h
.
If you have trouble with using patch you can also download a patched thread_pthread.hThanks.. I did have trouble. After pasting the patch from this page into a file, I wonder why I got this :
su-2.05# cd /usr/ports/lang/python21 su-2.05# patch <python-stack-size.patch Hmm... Looks like a new-style context diff to me... (Patch is indented 2 spaces.) The text leading up to this was: -------------------------- | *** /usr/ports/distfiles/python/Python-2.1.3/Python/thread_pthread.h Thu Jan 10 03:12:20 2002 | --- work/Python-2.1.3/Python/thread_pthread.h Thu Oct 17 21:59:48 2002 -------------------------- Patching file work/Python-2.1.3/Python/thread_pthread.h using Plan A... Hunk #1 failed at 128. Hunk #2 failed at 153. 2 out of 2 hunks failed--saving rejects to work/Python-2.1.3/Python/thread_pthread.h.rej done
make
make install FORCE_PKG_REGISTER=1
Or, if you want to test before overwriting your existing python, use
make install PREFIX=/some/tmp/path FORCE_PKG_REGISTER=1
and start your zope with/some/tmp/path/bin/python2.1 z2.py
This didn't work for me. I did :
make install PREFIX=~simon/bin FORCE_PKG_REGISTER=1
It installed a few things in ~simon/bin and the rest under /usr/local. To get my python installation consistent again, I did :
make deinstall make install FORCE_PKG_REGISTER=1
PageMaintainers: BobFinch, PieterB
I just e-mailed the maintainer of the FreeBSD? port. I hope it will be installed as default, because that would make Zope/Zwiki life much easier. -- PieterB
PieterB, 2003/03/29 20:17 GMT
This patch is applied to the FreeBSD? ports-tree later than: Thu Feb 6 11:27:49 2003.
Check if you have /usr/ports/lang/python21/files/patch-Python-thread_pthread.h-stacksize
-- PieterB
New input... --PieterB, 2003/06/21 21:35 GMT reply
Found article: How to Get Python 2.1.3, FreeBSD? and Plone to Happily Coexist (old, same kind of article, but nicer layout ;).
Also some new input on this comp.python.general thread (mostly based on patches for Python 2.2 and Python 2.3)
Wow, this should fix it... --PieterB, 2003/06/22 07:43 GMT reply
Ok, gmane has no way to browse a thread (stupid).
See groups.google.com thread on "Python 2.2.3 test_re.py fails with coredump on FreeBSD? 5.0, fails also on FreeBSD4?.8"
instead.
It mentions SF[ 740234 ]? test/build-failures on FreeBSD? stable/current.
Longterm options to fix this problem seem to be:
- building a threaded interpreter with the Linuxthreads port (
/usr/ports/devel/linuxthreads
) - check out the release21-maint or release22-maint branch of Python, and copy Modules/_sre.c" from there. This is a backport of the patch that reportedly fixes the problem for 2.3. (#553736 thread_pthread.h on FreeBSD?.
- upgrade to Python 2.1.4 when it's available.
Yikes --SimonMichael, 2003/06/22 11:57 GMT reply
This seems to be getting still more complicated. Good to see people working on it. At the moment I think the simplest fix for zwiki users is still to rebuild python with stack size 1<<20.
Yikes --PieterB, 2003/06/22 12:09 GMT reply
> This seems to be getting still more complicated. Good to see people working on
> it. At the moment I think the simplest fix for zwiki users is still to rebuild
> python with stack size 1<<20.
I wouldn't call that a fix. More of a workaround ;)
Pieter
Python 2.3 on FreeBSD? -- Thu, 12 May 2005 16:54:33 -0700 reply
If you want to have this workaround also on Python 2.3 on FreeBSD?, you should set the option "HUGE STACK SIZE" to on, when you install the lang/python23 port.
Jochen