简体   繁体   English

web.py + mod_wsgi文件上传问题

[英]Problem with web.py + mod_wsgi file upload

I'm working on a web.py app for uploading files and im having real problems with my deployment. 我正在开发一个web.py应用程序来上传文件,我的部署遇到了实际问题。 Basically I want to give the user a 'percentage uploaded' but this seems to be messing up severely when deployed on mod_wsgi. 基本上我想给用户一个'上传的百分比',但是当部署在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. 为了获得当前进度,我每秒通过客户端的GET请求获取给定会话的当前进度。

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. 似乎超过100kb的任何东西都不会增加进度变量。 The value is definitely incremented if placed outside of the loop (or before read() is ever called) or if the file is fairly small. 如果放在循环之外(或者在调用read()之前)或者文件相当小,则值肯定会增加。

Is it possible that wsgi is opening new threads for bigger files and therefore making my global counter only local to the upload thread? wsgi是否有可能为更大的文件打开新线程,从而使我的全局计数器仅在上载线程本地? Could it be something else. 可能是别的东西。

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. 实际上,Web服务器很可能使用单独的线程来提供以下请求,并且无法保证会话字典是相同的。 Try using the session object which is part of web.py. 尝试使用属于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 web.py会话示例

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM