web.py 的问题 + mod_wsgi文件上传

发布于 2024-10-16 12:04:33 字数 598 浏览 6 评论 0原文

我正在开发一个用于上传文件的 web.py 应用程序,但我的部署遇到了真正的问题。基本上我想给用户一个“上传的百分比”,但这在 mod_wsgi 上部署时似乎会严重混乱。主要上传的工作原理如下:

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”是一个全局字典,其中包含跟踪会话的对象。为了获取当前进度,我每秒通过客户端发出的 GET 请求获取给定会话的当前进度。

目前的问题是这仅适用于小上传。看起来超过 100kb 左右的任何内容都不会增加进度变量。如果放置在循环之外(或在调用 read() 之前)或者文件相当小,则该值肯定会递增。

wsgi 是否有可能为更大的文件打开新线程,从而使我的全局计数器仅在上传线程本地?会不会是别的什么。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

亢潮 2024-10-23 12:04:33

您不能仅使用全局字典来实现此目的。事实上,网络服务器很可能使用单独的线程来服务以下请求,并且不能保证会话字典是相同的。尝试使用属于 web.py 一部分的会话对象。它使用数据库或文件来存储可以跨不同线程或进程访问的数据。

web.py 会话示例

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文