Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8240811
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T20:37:06+00:00 2026-06-07T20:37:06+00:00

I have a front-end web server written in Twisted Web, that interfaces with another

  • 0

I have a front-end web server written in Twisted Web, that interfaces with another web server. Clients upload files to my front-end server, which then sends the files along to the back-end server. I’d like to receive the uploaded file, and then send an immediate response to the client before sending the file on to the back-end server. That way the client doesn’t have to wait for both uploads to occur before getting a response.

I’m trying to do this by starting the upload to the back-end server in a separate thread. The problem is, after sending a response to the client, I’m no longer able to access the uploaded file from the Request object. Here’s an example:

class PubDir(Resource):

    def render_POST(self, request):
        if request.args["t"][0] == 'upload':
            thread.start_new_thread(self.upload, (request,))

        ### Send response to client while the file gets uploaded to the back-end server:
        return redirectTo('http://example.com/uploadpage')

    def upload(self, request):
        postheaders = request.getAllHeaders()
        try:
            postfile = cgi.FieldStorage(
                fp = request.content,
                headers = postheaders,
                environ = {'REQUEST_METHOD':'POST',
                         'CONTENT_TYPE': postheaders['content-type'],
                        }
                )
        except Exception as e:
            print 'something went wrong: ' + str(e)

        filename = postfile["file"].filename

        file = request.args["file"][0]

        #code to upload file to back-end server goes here...

When I try this, I get an error: I/O operation on closed file.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T20:37:09+00:00Added an answer on June 7, 2026 at 8:37 pm

    You need to actually copy the file into a buffer in memory or into a tempfile on disk before you finish the request object (which is what happens when you redirect).

    So you are starting your thread and handing it the request object, it’s maybe opening a connection to your backend server and beginning to copy when you redirect which finishes the request and closes any associated tempfiles and you’re in trouble.

    Instead of passing the whole request to your thread a quick test would be trying to just pass the content of the request to your thread:

    thread.start_new_thread(self.upload, (request.content.read(),))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am starting a web application project that will have an Adobe Flex front-end
I have a Django webapp that has both a front-end, web-accessible component and an
I have a web service that creates files on the server. It works great
I have Nginx as my front-end web server listening on port 80. And certain
I have an application that consists of three parts: a front-end web shop for
I have built a web application which uses two web front end servers, the
I am building a site that will (obvisouly) have a front end public portion
I have made a front end for a program which test java (foo.class) binary
I have a lot of front-end code that would be more readable if I
I have the following code in the front end <asp:Content ID=Content1 ContentPlaceHolderID=cphMain runat=server> <script

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.