Got a unit test for the problem. According to hg bisect,

The first bad revision is:
changeset:   535:9b766e181f13
user:        Sergey Schetinin <ser...@maluke.com>
date:        Thu Feb 03 00:01:03 2011 +0200
summary:     * refactor req.body to use .make_body_seekable() instead of 
duplicating the code

-- 
You received this message because you are subscribed to the Google Groups 
"pylons-devel" group.
To post to this group, send email to pylons-devel@googlegroups.com.
To unsubscribe from this group, send email to 
pylons-devel+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/pylons-devel?hl=en.

"""
Test forking and Request.copy().

This test should be skipped on Windows.

Daniel Holth <dho...@fastmail.fm>
"""

from multiprocessing import Process
from webob import Request, Response
from wsgiref.simple_server import make_server

import httplib
import os
import random
import sys
import threading
import time
import urllib2

def watchdog():
    time.sleep(5)
    os._exit(1) # does not call atexit handlers etc.

def serve(server):
    threading.Thread(target=watchdog).start()
    server.serve_forever()

def test_fork():
    """See whether request.copy() is possible after a fork, [when the
    application is running in a background thread]."""
 
    counter = []
    def application(environ, start_response):
        if len(counter):
            os._exit(0)
        counter.append(1)
        r = Request(environ)
        r.copy()
        return Response(content_type="text/plain", body="Success!")(environ, start_response)
    
    port = random.randint(((1<<16)-1)/2, (1<<16)-1)
    # XXX retry if port is unavailable
    server = make_server('localhost', port, application)
    worker = Process(target=serve, args=(server,))
    worker.start()

    assert urllib2.urlopen("http://localhost:%d/"; % port, timeout=5).read() == "Success!"
    try:
        urllib2.urlopen("http://localhost:%d/"; % port).read() # exit on second request
    except (urllib2.HTTPError, httplib.BadStatusLine):
        # server called sys.exit() instead of answering request
        pass
    worker.join()

if __name__ == "__main__":
    test_fork()

Reply via email to