_mssql.connect() call hangs in mod_wsgi but not in python shell

518 views
Skip to first unread message

Frederick Yankowski

unread,
Nov 13, 2013, 2:53:07 PM11/13/13
to mod...@googlegroups.com
I've got a WSGI app that calls _mssql.connect() (pymssql package) to connect to an MS SQL database for reading. It was working fine with an older version of pymssql but with recent versions the call to connect() hangs. The httpd/mod_wsgi process is stalled until I restart Apace. So I'm looking for help figuring out what is going wrong.

I've created a trivial program that calls _mssql.connect() with both WSGI and shell wrappers. It works fine from the python shell but hangs every time when run in mod_wsgi.

When I watch the mod_wsgi process with strace I see it connecting to the MS SQL Server host over a socket and sending some traffic. It then calls futex() and hangs; nothing more happens until the process gets SIGKILL.

Here is the context.

OS:  Red Hat Enterprise Linux 6.4, 64bit

Python: 2.7.5, built from source, multi-threading enabled, shared libraries enabled.

mod_wsgi: version 3.4, built from source, against Python 2.7.5 (above).

Apache: 2.2.5, from RHEL 6.  Neither mod_php nor mod_python is installed.

freetds: 0.91 from RHEL 6. 

pymssql: Various versions. The latest stable, 2.0.1 from pip, fails. Revision 221 from https://code.google.com/p/pymssql is the most recent one that I've found to work.

Python configuration: installed into virtualenv.

mod_wsgi configuration: embedded mode. WSGIPythonHome set to a virtualenv.



Graham Dumpleton

unread,
Nov 13, 2013, 3:33:02 PM11/13/13
to mod...@googlegroups.com
Have they always used pyrex? I though they were pure Python.

Anyway, likely that they are now producing a package with a C extension that will not work in Python sub interpreters.

Are you setting the WSGIApplicationGroup directive to anything in your Apache configuration?

For background of potential issue, read:


If this is a new change they have made, will cause lots of grief going forward for people using mod_wsgi as sites stop working. :-(

Graham

--
You received this message because you are subscribed to the Google Groups "modwsgi" group.
To unsubscribe from this group and stop receiving emails from it, send an email to modwsgi+u...@googlegroups.com.
To post to this group, send email to mod...@googlegroups.com.
Visit this group at http://groups.google.com/group/modwsgi.
For more options, visit https://groups.google.com/groups/opt_out.

Frederick Yankowski

unread,
Nov 13, 2013, 4:34:39 PM11/13/13
to mod...@googlegroups.com
I don't know anything about pyrex. Pymssql uses Cython to translate a _mssql.pyx file to _mssql.c which it then compiles and links into _mssql.so.  That shared object comprises the entirety of the _mssql module.  _mssql.so links to libsybdb.so which is provided by the freetds package.

All this worked in an earlier version of pymssql/_mssql, including the Cython part.

I'm also pursuing this on the pymssql mailing list: https://groups.google.com/forum/#!topic/pymssql/Iee1E7NF9Fk

I'm not currently setting WSGIProcessGroup in my simple mod_wsgi test case. I do use it in the production app that is what I really care about.  In production I use daemon mode of mod_wsgi. I will look at that link you gave and try the %{GLOBAL} group.

Thanks.

Graham Dumpleton

unread,
Nov 13, 2013, 4:38:25 PM11/13/13
to mod...@googlegroups.com
The github repo actually talks about both Cython and pyrex.


I assumed pyrex based on pyx extension.

I also didn't say WSGIProcessGroup. I said WSGIApplicationGroup. Anyway, set it as explained and see what happens.

Graham

Frederick Yankowski

unread,
Nov 13, 2013, 5:09:18 PM11/13/13
to mod...@googlegroups.com
Sorry, I conflated WSGIApplicationGroup with WSGIProcessGroup.

Anyway, after I set WSGIProcessGroup to %{GLOBAL} the problem is gone.  _mssql.connect() no longer hangs.  I installed the latest pymssql package with pip and that too works fine.

So, thank you very much.

-Fred

Graham Dumpleton

unread,
Nov 13, 2013, 5:13:21 PM11/13/13
to mod...@googlegroups.com
Great.

I would raise it as a red flag with pymssql developers if still conversing with them as it would perhaps be a regression if the module now only works in Python main interpreter and not sub interpreters. Give them a link to that section in documentation for a partial explanation of issue.

Graham

Frederick Yankowski

unread,
Nov 13, 2013, 5:15:25 PM11/13/13
to mod...@googlegroups.com
And I got them mixed up again in my message. I actually set WSGIApplicationGroup to %{GLOBAL}.

Frederick Yankowski

unread,
Nov 13, 2013, 5:27:52 PM11/13/13
to mod...@googlegroups.com
I've already followed up on the pymssql list and gave them the link about GIL.
Reply all
Reply to author
Forward
0 new messages