L
Liam Slusser
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_address = 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
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_address = 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