Search code examples
streamzipcherrypy

cherrypy serve multiple requests / per connection


i have this code (on the fly compression and stream)

@cherrypy.expose
def backup(self):
    path = '/var/www/httpdocs'
    zip_filename = "backup" + t.strftime("%d_%m_%Y_") + ".zip"

    cherrypy.response.headers['Content-Type'] = 'application/zip'
    cherrypy.response.headers['Content-Disposition'] = 'attachment; filename="%s"' % (zip_filename,)

    #https://github.com/gourneau/SpiderOak-zipstream/blob/3463c5ccb5d4a53fc5b2bdff849f25bae9ead761/zipstream.py
    return ZipStream(path)

backup._cp_config = {'response.stream': True}

the problem i faced is when i'm downloading the file i cant browse any other page or send any other request until the download done... i think that the problem is that cherrypy can't serve more than one request at a time/ per user

any suggestion?


Solution

  • When you say "per user", do you mean that another request could come in for a different "session" and it would be allowed to continue?

    In that case, your issue is almost certainly due to session locking in cherrypy. You can read more about it is the session code. Since the sessions are unlocked late by default, the session is not available for use by other threads (connections) while the backup is still being processed.

    Try setting tools.sessions.locking = 'explicit' in the _cp_config for that handler. Since you’re not writing anything to the session, it’s probably safe not to lock at all.

    Good luck. Hope that helps.