jur9526 / couchdb-python

Automatically exported from code.google.com/p/couchdb-python
Other
0 stars 0 forks source link

Stuck on processing query's results in socket and urllib #157

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. create DB and fill it with documents.
2. run following steps:
server = Server('http://localhost:5984')
db = server['dabase']
doctst = Document.load(db,'6a94e53ea56c0e917b5cc7c31c01595f')
map_fun = '''function(doc) { if (doc.name=='Name1'){ emit(doc.valval);}}'''
results = db.query(map_fun)
row in db.query(map_fun):
            print row.key

Expected output - key value of a document. Instead of it, I see nothing for a 
long time. After the interruption I have got following:
^CTraceback (most recent call last):
  File "carpool_2.py", line 28, in <module>
    for row in db.query(map_fun):
  File "/usr/lib/pymodules/python2.6/couchdb/client.py", line 871, in __iter__
    for row in self.rows:
  File "/usr/lib/pymodules/python2.6/couchdb/client.py", line 893, in rows
    self._fetch()
  File "/usr/lib/pymodules/python2.6/couchdb/client.py", line 881, in _fetch
    data = self.view._exec(self.options)
  File "/usr/lib/pymodules/python2.6/couchdb/client.py", line 800, in _exec
    }, **self._encode_options(options))
  File "/usr/lib/pymodules/python2.6/couchdb/client.py", line 985, in post
    **params)
  File "/usr/lib/pymodules/python2.6/couchdb/client.py", line 1014, in _request
    resp, data = _make_request()
  File "/usr/lib/pymodules/python2.6/couchdb/client.py", line 1009, in _make_request
    body=body, headers=headers)
  File "/usr/lib/pymodules/python2.6/httplib2/__init__.py", line 1129, in request
    (response, content) = self._request(conn, authority, uri, request_uri, method, body, headers, redirections, cachekey)
  File "/usr/lib/pymodules/python2.6/httplib2/__init__.py", line 901, in _request
    (response, content) = self._conn_request(conn, request_uri, method, body, headers)
  File "/usr/lib/pymodules/python2.6/httplib2/__init__.py", line 871, in _conn_request
    response = conn.getresponse()
  File "/usr/lib/python2.6/httplib.py", line 986, in getresponse
    response.begin()
  File "/usr/lib/python2.6/httplib.py", line 391, in begin
    version, status, reason = self._read_status()
  File "/usr/lib/python2.6/httplib.py", line 349, in _read_status
    line = self.fp.readline()
  File "/usr/lib/python2.6/socket.py", line 397, in readline
    data = recv(1)
KeyboardInterrupt

What I have:
Ubuntu 10.04, Python 2.6.5-0, python-couchdb 0.6-1, couchdb 0.10.0-1, 
python-simplejson 2.0.9-1

Additional info:
I found information for the same issues. But it's not connected to CouchDB at 
all.
Run following lines in Python:
 import socket
 xml_source = "http://mlb.mlb.com/partnerxml/gen/news/rss/mlb.xml"
 import urllib
 fp = urllib.urlopen(xml_source)
 data = fp.read()
^CTraceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python2.6/socket.py", line 329, in read
    data = self._sock.recv(rbufsize)

It looks the same, however after small changes:
import urllib2
 data = urllib2.urlopen(xml_source)
 data
<addinfourl at 37053072 whose fp = <socket._fileobject object at 0x23500d0>>

It seems like Python's problem, however python-couchdb uses this library - 
urllib.

Please help to understand the root cause and find a solution.

Original issue reported on code.google.com by Ivan.Kos...@gmail.com on 7 Nov 2010 at 7:09

GoogleCodeExporter commented 9 years ago
Hi, Ivan!
About couchdb. 
How much documents in your database? If quite a lot so this query will be 
runned for a long time, because you had executed temporary view which must 
index all your documents before any result will be returned. What about 
permanent views? Is any problems with them?

About additional information.
I have not any ubuntu host to test, but this code works without any exceptions 
on windows, gentoo and slackware linux against same python version. I don't 
think that ubuntu have specific python sockets, but definely there is needed 
more information, e.g. test against local socket server, remote host, list 
cases when .read() is successive and when it have failed to analyze problem.

Original comment by kxepal on 9 Nov 2010 at 3:30

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
Hello.
I have only 6 documents. And according to my query I have to get 3 documents. 
However it is waiting even i do len on query:
map_fun = '''function(doc) { if (doc.name=='Name1'){ emit(doc.valval);}}'''
results = db.query(map_fun)
print len(results)

Following returns all documents one by one
for ID in db:
    doc = Document.load(db,ID)
    print doc
Is not query mechanism working?

Original comment by Ivan.Kos...@gmail.com on 14 Nov 2010 at 8:10

GoogleCodeExporter commented 9 years ago
Does the same map function work when pasted into Futon's "Temporary view"? Are 
there any errors in CouchDB's log files?

Original comment by matt.goo...@gmail.com on 14 Nov 2010 at 8:52

GoogleCodeExporter commented 9 years ago
Hello Matt.
First of all - shame on me. :-)
I appreciate you for your comment - check CouchDB log. I did not check it.
Issue is solved.
Step by step:
$ sudo tail /usr/local/var/log/couchdb/couch.log
[Sun, 14 Nov 2010 20:11:04 GMT] [error] [<0.2623.34>] OS Process Error 
<0.22953.40> :: {os_process_error,{exit_status,127}}

One small configuration issue is the cause of this error.
I tried to to following:
$ couchjs /usr/share/couchdb/server/main.js
/usr/local/lib/couchdb/bin/couchjs: error while loading shared libraries: 
libmozjs.so: cannot open shared object file: No such file or directory

$ cat /etc/ld.so.conf.d/xulrunner.conf
/usr/lib/xulrunner-1.9.2.10
/usr/lib/xulrunner-devel-1.9.2.10

$ ls /usr/lib/ | grep xulrunner
xulrunner
xulrunner-1.9.2.12
xulrunner-addons
xulrunner-devel-1.9.2.12

So, path is wrong. I fixed path here /etc/ld.so.conf.d/xulrunner.conf
and did following
$ sudo ldconfig

then
$ couchjs /usr/share/couchdb/server/main.js 
["reset"]

I got - true
Then I executed my query script...
It's working!

Original comment by Ivan.Kos...@gmail.com on 19 Nov 2010 at 7:59

GoogleCodeExporter commented 9 years ago
Great to hear it's sorted now. Unfortunately, this problem happens every time 
Ubuntu's xulrunner package is updated. If you add new entries to xulrunner.conf 
before upgrading and remove the old entries once the upgrade is complete you 
can avoid the problem.

Original comment by matt.goo...@gmail.com on 19 Nov 2010 at 8:49