Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > socketserver and postgres

Reply
Thread Tools

socketserver and postgres

 
 
Liam Slusser
Guest
Posts: n/a
 
      10-06-2003

Im having a really weird problem with socketserver and postgres.

Here is my setup...

Sun Netra T105
Sun Solaris 8 Generic_108528-23
Postgres 7.3.4 (also tried 7.3.2 same problem)
Python 2.3.2 (ive also tried 2.3 same problem)
psycopg (python postgres API) 1.1.9 (ive also tried pypgsql 2.4 with the
same problem)

It seems when i do a select of something that is large in size in the
postgres database it crashs when using socketserver. However i remove the
socketserver part and it runs great.

Here is the code im using...

DSN = 'dbname=mydb user=dbuser'

import SocketServer
import psycopg

dbconn = psycopg.connect(DSN)

class popSession(SocketServer.StreamRequestHandler):
"handles the pop session"

def handle(self):

db = dbconn.cursor()

message_idnr = 1473
msg=""

db.execute("select messageblk from messageblks where message_idnr=%d
and body_msg=1" % (m
essage_idnr))
msg = db.fetchone()[0]
#print msg
self.wfile.write(msg)

SocketServer.ThreadingTCPServer.allow_reuse_addres s = 1
SocketServer.StreamRequestHandler.rbufsize = 0
server = SocketServer.ThreadingTCPServer(("", 8003), popSession)
server.serve_forever()

This code works great..but once it gets to a large result set it crashs. I
can go into postgres and change messageblk (id 1473) to say "123 im here"
and then run the same code over and it works perfect.

The error message i get is:

----------------------------------------
Exception happened during processing of request from ('127.0.0.1', 32771)
Traceback (most recent call last):
File "/usr/local/lib/python2.3/SocketServer.py", line 463, in
process_request_thread
self.finish_request(request, client_address)
File "/usr/local/lib/python2.3/SocketServer.py", line 254, in
finish_request
self.RequestHandlerClass(request, client_address, self)
File "/usr/local/lib/python2.3/SocketServer.py", line 521, in __init__
self.handle()
File "tt.py", line 32, in handle
db.execute("select messageblk from messageblks where message_idnr=%d and
body_msg=1" % (message_idnr))
ProgrammingError: could not receive data from server: No such file or
directory

select messageblk from messageblks where message_idnr=1473 and body_msg=1
----------------------------------------


My first thought was something was messed up with psycopg, so i changed the
code to use pypgsql. It does the same thing!!!!!

Here is that error message...


Exception happened during processing of request from ('127.0.0.1', 32772)
Traceback (most recent call last):
File "/usr/local/lib/python2.3/SocketServer.py", line 463, in
process_request_thread
self.finish_request(request, client_address)
File "/usr/local/lib/python2.3/SocketServer.py", line 254, in
finish_request
self.RequestHandlerClass(request, client_address, self)
File "/usr/local/lib/python2.3/SocketServer.py", line 521, in __init__
self.handle()
File "ttt.py", line 34, in handle
db.execute("select messageblk from messageblks where message_idnr=%d and
body_msg=1" % (message_idnr))
File "/usr/local/lib/python2.3/site-packages/pyPgSQL/PgSQL.py", line 3091,
in execute
self.res = self.conn.conn.query('FETCH 1 FROM "%s"' % self.name)
OperationalError: could not receive data from server: Error 0

----------------------------------------


So heres the funny part though. I remove socketserver from the code and it
works perfect. This code works great...


DSN = 'dbname=mydb user=dbuser'

import psycopg

dbconn = psycopg.connect(DSN)

db = dbconn.cursor()

message_idnr = 1473
msg=""

db.execute("select messageblk from messageblks where message_idnr=%d and
body_msg=1" % (message_idnr))
msg = db.fetchone()[0]
print msg

That code works perfect. Prints out messageblk just like it suppost to.

Why does it break once i use socketserver?

thanks,
liam


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
SocketServer.ForkingMixIn and zombie processes nisimura@gmail.com Python 0 02-28-2007 04:45 PM
Postgres/Postgres-pr - some confusion Nick Black Ruby 1 11-16-2006 08:01 PM
SocketServer and timers alf Python 5 08-09-2006 02:03 AM
SocketServer and a Java applet listener google@phaedro.com Python 4 08-29-2005 09:48 PM
Examples and Tutorials of SocketServer? Milo K. Piffenpauffer Python 4 12-14-2003 07:49 AM



Advertisments