0

I'm working on a web.py app for uploading files and im having real problems with my deployment. Basically I want to give the user a 'percentage uploaded' but this seems to be messing up severely when deployed on mod_wsgi. The main upload works like this:

out = open(path, 'wb', 1000)

    while (True):

        packet = fileU.file.read(1000)

        if not packet:

            break

        else:

            out.write(packet)
            sessions[code].progress += 1

    out.close()

'Session' is a global dictionary that contains objects that keep track of sessions. To get the current progress I get the current progress for a given session via a GET request from the client every second.

The problem at the moment is that this only works for small uploads. It seems that anything over around 100kb will just not increment the progress variable. The value is definitely incremented if placed outside of the loop (or before read() is ever called) or if the file is fairly small.

Is it possible that wsgi is opening new threads for bigger files and therefore making my global counter only local to the upload thread? Could it be something else.

1 Answer 1

2

You can't just use a global dictionary for this. It is in fact very likely that the webserver is using a separate thread to serve the following requests, and there is no guarantee that the session dictionary is the same. Try using the session object which is part of web.py. It uses either a db or a file to store the data which can be accessed across different threads or processes.

web.py session example

Sign up to request clarification or add additional context in comments.

2 Comments

Is there anyway to store custom data in a session? And I can't seem to find how you retrieve a session in a request for a given user.
A session object basically has a dict interface, and you should be able to store any data you like. For instance if you set session[<user>] for one request, you should be able to retrieve session[<user>] in another request. You can more or less think about it as a really global dictionary.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.