Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PyEval_SaveThread: NULL tstate #46

Closed
natsuFairytail opened this issue Sep 28, 2015 · 46 comments
Closed

PyEval_SaveThread: NULL tstate #46

natsuFairytail opened this issue Sep 28, 2015 · 46 comments

Comments

@natsuFairytail
Copy link

On apache httpd2 2.2.15 on CentOS release 6.5 (Final)
I am getting

mod_python: Creating 32 session mutexes based on 256 max processes and 0 max threads.
[Sun Sep 27 03:28:04 2015] [notice] mod_python: using mutex_directory /var/run/mod_python/
Fatal Python error: PyEval_SaveThread: NULL tstate
[Sun Sep 27 03:28:04 2015] [notice] seg fault or similar nasty error detected in the parent process

Is there any way to resolve it

@grisha
Copy link
Owner

grisha commented Sep 29, 2015

This type of error usually means something isn't compiled correctly or there is a version mismatch between mod_python and the Python libs being used, hard to check without some debugging.

@natsuFairytail
Copy link
Author

I am using it with python 2.7.10.
in order to configure it i used these commands
for PYTHON
./configure --enable-shared
then created the file python2.7.conf in /etc/ld.so.conf.d/
then ldconfig

then configure mod_python as
./configure --with-python=/usr/local/bin/python2.7 --with-mutex-dir=/var/run/mod_python/ --with-max-locks=32

let me know if i can provide you with some more debug information

@CheyenneWills
Copy link

I'm running into the same problem. (gentoo system) -- rebuilt both apache and mod_python

Any suggestions for debugging or providing additional information?

@natsuFairytail
Copy link
Author

grisha you said it require debugging but you haven't provided what you need for debugging.

I an pretty sure me and Cheyenne can provide you logs.

@grisha
Copy link
Owner

grisha commented Nov 18, 2015

@natsuFairytail Sorry - with my schedule I haven't been able to devote any time to this, but the kind of debugging I meant was just probably attaching to the httpd process with gdb and figuring out why tstate is null. This error isn't generated by mod_python, it's coming from the CPython code, so you'll need to have all of httpd, Python and mod_python compiled with debugging enabled, which might be a little involved if you haven't done this before, sorry!

@CheyenneWills
Copy link

If there is something specific, I can do the debugging (including setting debugging for both python and apache). If you have some specific "break points" or memory values you would like to see let me know.

@CheyenneWills
Copy link

Just doing a quick debug (with debug symbols for apache, mod_python and CPython) here is the bt at the SIGABRT.

If you can let me know what to look for I can go digging

(gdb) continue
Continuing.

Program received signal SIGUSR1, User defined signal 1.
0x00007fbd7b4f32d3 in select () from /lib64/libc.so.6
(gdb) continue
Continuing.

Program received signal SIGABRT, Aborted.
0x00007fbd7b443b37 in raise () from /lib64/libc.so.6
(gdb) bt
#0  0x00007fbd7b443b37 in raise () from /lib64/libc.so.6
#1  0x00007fbd7b444f0a in abort () from /lib64/libc.so.6
#2  0x00007fbd72f8b3ae in Py_FatalError (msg=msg@entry=0x7fbd72fd04d0 "PyEval_SaveThread: NULL tstate") at /var/tmp/portage/dev-lang/python-2.7.10/work/Python-2.7.10/Python/pythonrun.c:1695
#3  0x00007fbd72f6938c in PyEval_SaveThread () at /var/tmp/portage/dev-lang/python-2.7.10/work/Python-2.7.10/Python/ceval.c:343
#4  0x00007fbd7327457a in python_init (p=0x674138, ptemp=<optimized out>, plog=<optimized out>, s=0x67b870) at mod_python.c:794
#5  0x0000000000439bd3 in ap_run_post_config (pconf=pconf@entry=0x674138, plog=0x67c178, ptemp=0x67e188, s=s@entry=0x67b870) at config.c:91
#6  0x0000000000425a3a in main (argc=41, argv=0x7ffc55f32c88) at main.c:742

@grisha
Copy link
Owner

grisha commented Nov 18, 2015

in python_init (p=0x674138, ptemp=<optimized out>, plog=<optimized out>, s=0x67b870) at mod_python.c:794 is a clue - which points to this line https://github.com/grisha/mod_python/blob/3.5.x/src/mod_python.c#L794. One theory is that there is some kind of a mismatch with WITH_THREADS - e.g. Python is compiled with threads but mod_python isn't or vice versa. PyEval_SaveThread() is documented here https://docs.python.org/2/c-api/init.html

@CheyenneWills
Copy link

Both Python and mod_python are compiled with WITH_THREAD

I was looking at the mod_python code, especially the comments around the use of the initialized variable. Could it be that the python framework got unloaded?

So the idea with the PyEval_SaveThread is that it releases the Python GIL. Could this be a case where the GIL wasn't held because of the reload. -OR- could it be that PyThreadState global_tstate is getting wiped during the module reload? -- is there something that I can "poke" at in gdb to determine this for you?

@grisha
Copy link
Owner

grisha commented Nov 19, 2015

There is no chance of anything happening between line 780 (PyEval_InitThreads()) and 794 (PyEval_SaveThread()). You can look at what each of the do to get a better understanding:

PyEval_InitThreads: https://github.com/python/cpython/blob/2.7/Python/ceval.c#L249
PyEval_SaveThread: https://github.com/python/cpython/blob/2.7/Python/ceval.c#L339

Another possibility is that somehow mod_python is initialized more than once, and PyEval_InitThreads() is called more than once in parallel threads?

@CheyenneWills
Copy link

So stepping through the code in python_init

we get to the test in line 771

if (initialized == 0 || !Py_IsInitialized())

the variable initialized is 0, and poking around the state at this point is that Py_IsInitialized is "true"

Calling the Py_Initialized(), which calls Py_InitializeEx(1).
Py_InitializeEx returns immediately since the python static variable initialized is 1

Next mod_python calls PyEval_InitThreads() which immediately returns because the python static variable interpreter_lock is not null.

Next mod_python calls PyEval_SaveThread() which calls PyThreadState_Swap(NULL) which returns _PyThreadStateCurrent (which is NULL). PyEval_SaveThread() tests the return from the PyThreadState_Swap and this is where the fatal error happens.

So.. it looks like Python thinks it's initialized, but it appears that the _PyThreadStateCurrent is NULL.

(BTW -- sorry if I happen to state something obvious -- this is my first time through the mod_python internals, and I haven't done anything with invoking the python interpreter before..)

@grisha
Copy link
Owner

grisha commented Nov 19, 2015

Hrm... Could it be that something else initializes Python, e.g. do you have mod_wsgi loaded for example?

@CheyenneWills
Copy link

I have a python ReWriteMap routine that is written in Python, and mod_passenger -- which introduced it's own python handler. I ran a test with mod_passenger disabled and things still failed.

@CheyenneWills
Copy link

I disabled the ReWriteMap, and mod_passenger -- Still fails with same error

@CheyenneWills
Copy link

Doing some more tracing, I put breakpoints at python_cleanup and python_cleanup_handler before invoking the apache reload. Neither of these break points hit. Is there supposed to be some code within mod_python that handles the "shutdown" request? I saw some code commented out with a references to MODPYTHON-109 and not invoking cleanup.

@grisha
Copy link
Owner

grisha commented Nov 19, 2015

I'd try disabling mod_python, restarting httpd and attaching to it with gdb and see if any of the Python symbols are loaded, e.g. setting a breakpoint on some CPython code, as well as double check that mod_python is indeed not loaded, just to eliminate that possibility.

@CheyenneWills
Copy link

I removed all my references to mod_python (commented out the location that has the python handlers), attached gdb and did a breakpoint on PyEval_SaveThread. gdb asked if I wanted to set the breakpoint pending on a future shared library load.

@grisha
Copy link
Owner

grisha commented Nov 19, 2015

So we know the problem is that Py_IsInitialized() is returning true - the only place in the code where I see it is set is: https://github.com/python/cpython/blob/2.7/Python/pythonrun.c#L179. It somehow must be happening before mod_python's call to Py_Initialize().

@CheyenneWills
Copy link

I put several break points and watches on.

It looks like the lock isn't changing when the mod_python is reloaded. I wonder if the lock is being held across mod_python's module reload. I would think that mod_python should release any locks it owns when it's dropped, -or- it should remember that it has the lock across the module reload.

(gdb) info break
Num     Type           Disp Enb Address            What
1       breakpoint     keep y   0x00007fc1164a2220 in python_init at mod_python.c:694
2       breakpoint     keep y   0x00007fc116197170 in PyEval_InitThreads at /var/tmp/portage/dev-lang/python-2.7.10/work/Python-2.7.10/Python/ceval.c:251
3       breakpoint     keep y   0x00007fc1161ba9f0 in Py_InitializeEx at /var/tmp/portage/dev-lang/python-2.7.10/work/Python-2.7.10/Python/pythonrun.c:163
4       acc watchpoint keep y                      'pythonrun.c'::initialized
5       acc watchpoint keep y                      _PyThreadState_Current
6       acc watchpoint keep y                      interpreter_lock
(gdb) print interpreter_lock
$1 = (PyThread_type_lock) 0x943a90
(gdb) print _PyThreadState_Current
$2 = (PyThreadState *) 0x0
(gdb) print 'pythonrun.c'::initialized
$3 = 1
(gdb) continue
Continuing.
.... apache reload happens here....
Program received signal SIGUSR1, User defined signal 1.
0x00007fc11e7212d3 in select () from /lib64/libc.so.6
(gdb) continue
Continuing.
warning: Temporarily disabling breakpoints for unloaded shared library "/usr/lib64/apache2/modules/mod_python.so"

Breakpoint 1, python_init (p=0x674138, ptemp=0x67c178, plog=0x67e188, s=0x67b870) at mod_python.c:694
694 {
(gdb) print interpreter_lock
$4 = (PyThread_type_lock) 0x943a90
(gdb) print _PyThreadState_Current
$5 = (PyThreadState *) 0x0
(gdb) print 'pythonrun.c'::initialized
$6 = 1
(gdb) 

@CheyenneWills
Copy link

Here is my theory (and I may have missed something in poking around in this)

During apache graceful restart, all the modules get unloaded. It appears that the mod_python isn't called during the "unload" phase. The python interpreter is left loaded while the mod_python code has the interpreter lock. When apache reloads the modules, mod_python is loaded and python_init is invoked, and chugs its way through the initialization thinking that it's the first time. Python thinks it's already initialized and "assumes" that mod_python has the current lock. However mod_python thinks that it is initializing and assumes that it doesn't have the current lock.

I would look at commit 4412c11 to see if it broke the graceful restart.

Possible solutions? -- add code that captures the graceful restart, store what mod_python thingks is the current python state and test/restore it during python_init --or-- add logic that keeps the current state in persistent memory.

Again... I'm not familiar enough with either the apache internals, mod_python, or the details of managing the python interpreter in a threaded environment, to be sure if my theory is even close to correct or if the solutions are even in the right ball park.

@grisha
Copy link
Owner

grisha commented Nov 20, 2015

Thank you, when I get a chance I'll take a look at this.

@CheyenneWills
Copy link

Thank you. I'll be heading out for the evening. Let me know if there is anything you would like me to try/debug (though it will have to be in the morning)

@robmoss2k
Copy link

I'm also seeing this issue on Amazon Linux, using httpd 2.4.16, Python 2.7.10 and mod_python 3.5.0. During a restart now or a graceful restart, httpd will die, with the error previously noted:

[Thu Nov 19 03:32:01.954307 2015] [mpm_prefork:notice] [pid 5885] AH00173: SIGHUP received. Attempting to restart
[Thu Nov 19 03:32:02.005063 2015] [auth_digest:notice] [pid 5885] AH01757: generating secret for digest authentication ...
[Thu Nov 19 03:32:02.007938 2015] [lbmethod_heartbeat:notice] [pid 5885] AH02282: No slotmem from mod_heartmonitor
[Thu Nov 19 03:32:02.008150 2015] [:notice] [pid 5885] mod_python: Creating 8 session mutexes based on 256 max processes and 0 max threads.
[Thu Nov 19 03:32:02.008157 2015] [:notice] [pid 5885] mod_python: using mutex_directory /tmp
Fatal Python error: PyEval_SaveThread: NULL tstate
[Thu Nov 19 03:32:02.008199 2015] [core:notice] [pid 5885] AH00060: seg fault or similar nasty error detected in the parent process

It appears to happen on every "graceful restart" and "restart now" ("apachectl -k restart" (HUP) and "apachectl -k graceful" (USR1)).

@robmoss2k
Copy link

I can also confirm that this happens with mod_python 3.5.0 and the current git branch, but not with 3.4.1 - that stays alive.

@grisha
Copy link
Owner

grisha commented Nov 23, 2015

@robmoss2k thanks for the info, interesting, there seems to be an affinity with the latest Pythons. If I get a chance, I'll take a look at it over Thanksgiving, but PR's are always welcome! ;)

@CheyenneWills
Copy link

@grisha Let me know if you would like something tested. I can recreate this at will and I can easily make updates for testing.

@SBBH
Copy link

SBBH commented Nov 25, 2015

I also have this problem on FreeBSD 10.2 x64 running apache 2.4, python 2.7.10, mod_python 3.5.0. Apache will run for a day or so but then crash with the following in the logs:

[:notice] [pid 7108] mod_python: Creating 8 session mutexes based on 256 max processes and 0 max threads.
[:notice] [pid 7108] mod_python: using mutex_directory /tmp Fatal Python error: PyEval_SaveThread: NULL tstate
[core:notice] [pid 7108] AH00060: seg fault or similar nasty error detected in the parent process

I'm not so sure what the steps are for getting a backtrace but "gdb /usr/local/sbin/httpd /root/httpd.core" yields the following.

GNU gdb 6.1.1 [FreeBSD]
Copyright 2004 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for details.
This GDB was configured as "amd64-marcel-freebsd"...(no debugging symbols found)...
Core was generated by `httpd'.
Program terminated with signal 6, Aborted.
Reading symbols from /usr/local/lib/libpcre.so.1...(no debugging symbols found)...done.
Loaded symbols for /usr/local/lib/libpcre.so.1
Reading symbols from /usr/local/lib/libaprutil-1.so.0...(no debugging symbols found)...done.
Loaded symbols for /usr/local/lib/libaprutil-1.so.0
Reading symbols from /usr/local/lib/libexpat.so.1...(no debugging symbols found)...done.
Loaded symbols for /usr/local/lib/libexpat.so.1
Reading symbols from /usr/local/lib/libapr-1.so.0...(no debugging symbols found)...done.
Loaded symbols for /usr/local/lib/libapr-1.so.0
Reading symbols from /lib/libcrypt.so.5...(no debugging symbols found)...done.
Loaded symbols for /lib/libcrypt.so.5
Reading symbols from /lib/libthr.so.3...(no debugging symbols found)...done.
Loaded symbols for /lib/libthr.so.3
Reading symbols from /lib/libc.so.7...(no debugging symbols found)...done.
Loaded symbols for /lib/libc.so.7
Reading symbols from /lib/libm.so.5...(no debugging symbols found)...done.
Loaded symbols for /lib/libm.so.5
Reading symbols from /usr/local/lib/libpython2.7.so.1...(no debugging symbols found)...done.
Loaded symbols for /usr/local/lib/libpython2.7.so.1
Reading symbols from /usr/local/lib/libintl.so.8...(no debugging symbols found)...done.
Loaded symbols for /usr/local/lib/libintl.so.8
Reading symbols from /lib/libutil.so.9...(no debugging symbols found)...done.
Loaded symbols for /lib/libutil.so.9
Reading symbols from /usr/local/lib/python2.7/lib-dynload/_locale.so...(no debugging symbols found)...done.
Loaded symbols for /usr/local/lib/python2.7/lib-dynload/_locale.so
Reading symbols from /usr/local/libexec/apache24/mod_authn_file.so...(no debugging symbols found)...done.
Loaded symbols for /usr/local/libexec/apache24/mod_authn_file.so
Reading symbols from /usr/local/libexec/apache24/mod_authn_core.so...(no debugging symbols found)...done.
Loaded symbols for /usr/local/libexec/apache24/mod_authn_core.so
Reading symbols from /usr/local/libexec/apache24/mod_authz_host.so...(no debugging symbols found)...done.
Loaded symbols for /usr/local/libexec/apache24/mod_authz_host.so
Reading symbols from /usr/local/libexec/apache24/mod_authz_groupfile.so...(no debugging symbols found)...done.
Loaded symbols for /usr/local/libexec/apache24/mod_authz_groupfile.so
Reading symbols from /usr/local/libexec/apache24/mod_authz_user.so...(no debugging symbols found)...done.
Loaded symbols for /usr/local/libexec/apache24/mod_authz_user.so
Reading symbols from /usr/local/libexec/apache24/mod_authz_core.so...(no debugging symbols found)...done.
Loaded symbols for /usr/local/libexec/apache24/mod_authz_core.so
Reading symbols from /usr/local/libexec/apache24/mod_access_compat.so...(no debugging symbols found)...done.
Loaded symbols for /usr/local/libexec/apache24/mod_access_compat.so
Reading symbols from /usr/local/libexec/apache24/mod_auth_basic.so...(no debugging symbols found)...done.
Loaded symbols for /usr/local/libexec/apache24/mod_auth_basic.so
Reading symbols from /usr/local/libexec/apache24/mod_reqtimeout.so...(no debugging symbols found)...done.
Loaded symbols for /usr/local/libexec/apache24/mod_reqtimeout.so
Reading symbols from /usr/local/libexec/apache24/mod_filter.so...(no debugging symbols found)...done.
Loaded symbols for /usr/local/libexec/apache24/mod_filter.so
Reading symbols from /usr/local/libexec/apache24/mod_mime.so...(no debugging symbols found)...done.
Loaded symbols for /usr/local/libexec/apache24/mod_mime.so
Reading symbols from /usr/local/libexec/apache24/mod_log_config.so...(no debugging symbols found)...done.
Loaded symbols for /usr/local/libexec/apache24/mod_log_config.so
Reading symbols from /usr/local/libexec/apache24/mod_env.so...(no debugging symbols found)...done.
Loaded symbols for /usr/local/libexec/apache24/mod_env.so
Reading symbols from /usr/local/libexec/apache24/mod_headers.so...(no debugging symbols found)...done.
Loaded symbols for /usr/local/libexec/apache24/mod_headers.so
Reading symbols from /usr/local/libexec/apache24/mod_setenvif.so...(no debugging symbols found)...done.
Loaded symbols for /usr/local/libexec/apache24/mod_setenvif.so
Reading symbols from /usr/local/libexec/apache24/mod_version.so...(no debugging symbols found)...done.
Loaded symbols for /usr/local/libexec/apache24/mod_version.so
Reading symbols from /usr/local/libexec/apache24/mod_unixd.so...(no debugging symbols found)...done.
Loaded symbols for /usr/local/libexec/apache24/mod_unixd.so
Reading symbols from /usr/local/libexec/apache24/mod_status.so...(no debugging symbols found)...done.
Loaded symbols for /usr/local/libexec/apache24/mod_status.so
Reading symbols from /usr/local/libexec/apache24/mod_autoindex.so...(no debugging symbols found)...done.
Loaded symbols for /usr/local/libexec/apache24/mod_autoindex.so
Reading symbols from /usr/local/libexec/apache24/mod_cgi.so...(no debugging symbols found)...done.
Loaded symbols for /usr/local/libexec/apache24/mod_cgi.so
Reading symbols from /usr/local/libexec/apache24/mod_dir.so...(no debugging symbols found)...done.
Loaded symbols for /usr/local/libexec/apache24/mod_dir.so
Reading symbols from /usr/local/libexec/apache24/mod_alias.so...(no debugging symbols found)...done.
Loaded symbols for /usr/local/libexec/apache24/mod_alias.so
Reading symbols from /usr/local/libexec/apache24/libphp5.so...(no debugging symbols found)...done.
Loaded symbols for /usr/local/libexec/apache24/libphp5.so
Reading symbols from /usr/local/lib/libxml2.so.2...(no debugging symbols found)...done.
Loaded symbols for /usr/local/lib/libxml2.so.2
Reading symbols from /lib/libz.so.6...(no debugging symbols found)...done.
Loaded symbols for /lib/libz.so.6
Reading symbols from /usr/lib/liblzma.so.5...(no debugging symbols found)...done.
Loaded symbols for /usr/lib/liblzma.so.5
Reading symbols from /usr/local/libexec/apache24/mod_python.so...(no debugging symbols found)...done.
Loaded symbols for /usr/local/libexec/apache24/mod_python.so
Reading symbols from /usr/local/libexec/apache24/mod_auth_digest.so...(no debugging symbols found)...done.
Loaded symbols for /usr/local/libexec/apache24/mod_auth_digest.so
Reading symbols from /usr/local/lib/php/20131226/xml.so...(no debugging symbols found)...done.
Loaded symbols for /usr/local/lib/php/20131226/xml.so
Reading symbols from /libexec/ld-elf.so.1...(no debugging symbols found)...done.
Loaded symbols for /libexec/ld-elf.so.1
#0  0x000000080169d64a in thr_kill () from /lib/libc.so.7
[New Thread 802006400 (LWP 100948/<unknown>)]

Let me know if there's anything else that would be helpful.

I've also posted this to FreeBSD Bugzilla.

@grisha
Copy link
Owner

grisha commented Nov 28, 2015

I've been able to replicate the issue: it happens with worker MPM after a graceful restart. Also by way of experiment tracked down that it starts happening with the Python release 2.7.9 (2.7.8 is ok). Haven't looked at what exactly causes it or how to fix it yet, may be later this weekend if I get some time.

@grisha
Copy link
Owner

grisha commented Nov 30, 2015

The Python commit that started causing this is: python/cpython@909877f and I have verified that simply import _locale breaks graceful restart. At this point no idea why this may be, suggestions welcome!

@CheyenneWills
Copy link

I just ran a test, I "backed out" the above changes (I just edited /usr/lib64/python2.7/re.py and undid the _locale changes).

I was able to do a graceful restart of apache without problems.

I then went back and changed my modified re.py to just do an import on _locale and that change alone was enough to break the graceful reload

@CheyenneWills
Copy link

The only thing that I can currently think is that python's _locale.so module is dynamically loaded after mod_python is loaded and because there is a reference, it's holding the python module in memory over the restart.

@grisha grisha closed this as completed in 5bb5d6d Dec 2, 2015
@grisha
Copy link
Owner

grisha commented Dec 2, 2015

I believe the latest check-in fixes this - could people try this in their set ups and confirm it?

@grisha grisha reopened this Dec 2, 2015
@CheyenneWills
Copy link

Initial testing looks good so far. Will update after further testing

@CheyenneWills
Copy link

Sorry about the delay on getting back. The fix seems to have "fixed" the problem in my environment.

@SBBH
Copy link

SBBH commented Dec 11, 2015

Seems to be working now for me as well. Apache hasn't crashed since applying this fix.

@robmoss2k
Copy link

Six weeks of straight uptime. Looking good!

@adaugherity
Copy link

I tested this adding this patch to the openSUSE package, and while it did fix the "apache crashes on reload" problem, it introduced a new one:

[Tue May 24 18:08:29.605224 2016] [:error] [pid 29563] make_obcallback: could not import mod_python.apache.\n
ImportError: No module named mod_python.apache
[Tue May 24 18:08:29.605855 2016] [:error] [pid 29563] make_obcallback: Python path being used "['/usr/lib/python27.zip', '/usr/lib64/python2.7/', '/usr/lib64/python2.7/plat-linux2', '/usr/lib64/python2.7/lib-tk', '/usr/lib64/python2.7/lib-old', '/usr/lib64/python2.7/lib-dynload']".
[Tue May 24 18:08:29.605950 2016] [:error] [pid 29563] get_interpreter: no interpreter callback found.

I'm running ViewVC under mod_python, and these three lines are logged with every page load. ViewVC still appears to work fine, strangely.

Notably, this path is missing all the site-package directories listed in sys.path in a CLI python session, including /usr/lib64/python2.7/site-packages, which is where mod_python is packaged under. This seems like a Catch-22...

I tried adding this directory to the PythonPath in the apache config, but that had no effect.

@SBBH
Copy link

SBBH commented May 25, 2016

I noticed the same thing but it was happening for me before the patch. But, other than the extra lines in the log file, everything still seemed to work so I didn't give it much thought.

@grisha
Copy link
Owner

grisha commented May 25, 2016

I believe the initial PythonPath comes form libpython, so it's a function of how Python is configured, not mod_python (at least that's how I remember it).

@adaugherity
Copy link

But you should also be able to change it via apache, no? Or is it stripping out anything it thinks is a "site" directory?

I did not have these errors before the patch. This is how python is configured:

Python 2.7.9 (default, Dec 13 2014, 18:02:08) [GCC] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> print sys.path
['', '/usr/lib/python27.zip', '/usr/lib64/python2.7', '/usr/lib64/python2.7/plat-linux2', '/usr/lib64/python2.7/lib-tk', '/usr/lib64/python2.7/lib-old', '/usr/lib64/python2.7/lib-dynload', '/usr/lib64/python2.7/site-packages', '/usr/local/lib64/python2.7/site-packages', '/usr/local/lib/python2.7/site-packages', '/usr/lib/python2.7/site-packages']

The last four entries (all site-packages of some form) are missing from the path in the apache error log, as is the viewvc directory set below. Some directories are not present but that doesn't seem to matter.

ViewVC apache configuration:

        ScriptAlias /viewvc "/srv/viewvc/bin/mod_python/myviewvc.py"
        <Location /viewvc>
                AddHandler python-program .py
                PythonPath "['/srv/viewvc/bin/mod_python']+sys.path"
                PythonHandler handler
        </Location>

I tried setting PythonPath "['/srv/viewvc/bin/mod_python','/usr/lib64/python2.7/site-packages']+sys.path" but that did not help.

@panicfarm
Copy link

panicfarm commented May 25, 2016

I had the same error make_obcallback: Python path being used ... after the patch (but not before). The error was fixed by setting the environmental variable
PYTHONPATH=/usr/local/encap/python-2.7.11/lib/python2.7/site-packages/
in the shell that starts Apache.
I think this is because site module in python adds site-packages to sys.path, however since it was removed with Py_NoSiteFlag = 1;, the main interpreter did not have it when Apache first started (but the sub-interpreters probably still loaded site, thus the requests were served correctly)

@grisha
Copy link
Owner

grisha commented May 26, 2016

@alecm3 I think you nailed it, I'll see about potentially fixing this, but until then it looks like it's a benign error.

@calin-iorgulescu
Copy link
Contributor

I had the same error make_obcallback: Python path being used ... on Ubuntu 16.04 . Reverting 5bb5d6d no longer breaks apache2's graceful restart for me. Tried:

# apachectl graceful
# apachectl -k graceful
# apachectl restart
# apachectl -k restart
Server Version: Apache/2.4.27 (Ubuntu) mod_python/3.5.0-5d24521 Python/2.7.14
    OpenSSL/1.0.2g
Server MPM: prefork
Server Built: 2017-09-18T15:05:48
Python 2.7.14 (default, Sep 23 2017, 22:06:14) 
[GCC 7.2.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> 

I suggest the site.py-import fix be limited to python versions prior to 2.7.14 . Please see pull request #68 .

cmalek pushed a commit to caltechads/amazon2-mod-python that referenced this issue Dec 20, 2019
* Had to properly link in libpython2.7.so
* Had to patch to fix grisha/mod_python#46 in python-2.7.16
@grisha grisha closed this as completed Jan 10, 2020
@hbfl
Copy link

hbfl commented Mar 1, 2020

this issue come back with Python 2.7.17

[Sun Mar 01 11:59:19.859132 2020] [mpm_event:notice] [pid 9500:tid 139896762713984] AH00489: Apache/2.4.41 (Unix) mod_python/3.5.0=none Python/2.7.17
Fatal Python error: PyEval_SaveThread: NULL tstate

mod_python was build from gitclone 2020-02-09

@hbfl
Copy link

hbfl commented Mar 1, 2020

see: https://bugs.python.org/issue20891
...
Since only two users complained about https://bugs.python.org/issue20891 in 3 years, I agree that it's ok to not fix Python 2.7 and 3.6. The workaround is to call PyEval_InitThreads() before starting the first thread.

I wasn't excited to make such stable in stable 2.7 and 3.6 anyway :-)
...

@hbfl
Copy link

hbfl commented Mar 9, 2020

apache handling musst be stop and start, restart give this error
fixed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants