Hi
I have GUI that will interact with a postgres database, using psycopg2. I have db connection in a multiprocessing process, and send SQL via a multiprocessing queue, and receive via another queue.
The problem is that the speed is very very slow. A simple select * from a small table (30 rows) can be 1/10th of a second, or can take over one second.
Does any one have any clues as to why it's so slow?
New Information: It works fine on winxp, exact same code, so the intermittent delay is only happening on my linux box (ubuntu 9.10)
More info: Having stubbed out the select it appears it's not the problem.
Here is the main part of the db class.
class DataBase(multiprocessing.Process):
def __init__(self, conn_data, in_queue, out_queue):
multiprocessing.Process.__init__(self)
self.in_queue = in_queue
self.out_queue = out_queue
self.conn_data = conn_data
self.all_ok = True
def run(self):
proc_name = self.name
self.conn = self.get_connection(self.conn_data)
print("Running ", self.name)
while True:
next_job = self.in_queue.get()
print("Next Job: ",next_job)
if next_job is None:
# Stop Process
break
SQL = next_job[0]
callback = next_job[1]
result = self.execute(SQL)
self.out_queue.put((result, callback))
print("Closing connection ", self.name)
self.conn.close()
return
And in the GUI I have this:
def recieve_data(self):
"Revived data on the queue. Data is a tuple of the actual data and a calback name."
if self.recieve_queue.empty() == False:
data = self.recieve_queue.get()
callback_name = data[1]
try:
callback = getattr(self, callback_name)
callback(data[0])
except AttributeError as e:
util.error_ui(err = e)
self.check_data_timeout = None
return False # Stop checking.
return True # Have the main loop keep checking for data.
def request_data(self, SQL, callback):
self.send_queue.put((SQL, callback))
self.check_data_timeout = gobject.timeout_add(50, self.recieve_data) # Poll the database recieved_queue