> > How can I make a long running request without reseting
connection ?.
I recently had a similar problem and here is my solution.

In the servlet I spawn a new thread and then constantly push
output to the browser to keep the connection open.  It works via
apache, but not from the IIS .exe adapter

Geoffrey and Tavis both helped out when I hit this problem a
while ago and I never mentioned the working solution.

The next incarnation is going to pop up a window that will
refresh every 5 seconds and when the job is done it will use
Javascript to close itself and redirect the main page to the next
step.

-Aaron

The code:

in the servlet:
 def writeContent(self):
 <snip>
  if (self.session().hasValue('rs')):
   self.session().delValue('rs')
  app = trans.application()
  app._processor = p = SQLRunner(app,sess,maxRecords)
  p.start()
  self.writeln('Searching.')
  self.response().flush()
    #below is the loop where I check for completion, write a "."
and flush it to the browser
  while not ( self.session().hasValue('rs') or
self.session().hasValue('error')):
   self.writeln('.')
   self.response().flush()
   sleep(2)

  if self.session().hasValue('error'):
   self.writeln('There has been an error, please start over')

Then I have the following class for SQLRunner.

from threading import Thread
from time import sleep
class SQLRunner:
   def __init__(self, app, sess, maxRecs):
       self._app = app
       self._thread = Thread(target=self.run)
       self._sess = sess
       self._maxRecs = maxRecs

   def start(self):
       self._thread.start()

   def run(self):
       if self._app.running:
         sess = self._sess
         if (sess.hasValue('CurrentSQL')):
           currentSQL= sess.value('CurrentSQL', None)
           currentSQL.SQLType('Full')
           user=sess.value('user')
           currentSQL.addWhere('Groups','IN',user.groups)
           SQL = currentSQL.genSQL()+" LIMIT " +
str(self._maxRecs + 1)
           rs = CSData.runQuery(user, SQL )
           count=len(rs)
           print 'returned ', count, 'records'
           sess.setValue('sql',SQL)
           sess.setValue('rsSize',len(rs))
           sess.setValue('rs',rs)
      else:
           sess.setValue('error','There is no current query')


_______________________________________________
Webware-discuss mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/webware-discuss

Reply via email to