Opened 12 years ago

Closed 11 years ago

#1619 defect closed duplicate (duplicate)

Reloading html page with unchanged CSS generates traceback

Reported by: jacob Owned by:
Priority: normal Milestone: Web2-Gold-Master
Component: web2 Keywords:
Cc: Branch:
Author:

Description (last modified by Jean-Paul Calderone)

Here is an example, based on the web2 demo file. To repeat:

  1. Put this file in a directory
  2. Create a CSS file called "schedcss" in the same directory. Suitable content is "h1 {font-size: 10pt}"
  3. Start server with "twistd -ny <filename>
  4. Point browser to "http://localhost:8080/". This should load fine.
  5. Press reload button. This should generate traceback.
  6. Do "touch schedcss".
  7. Press reloadbutton again. This should not generate a traceback.

#!/usr/bin/env python2.4
# Copyright (c) 2001-2004 Twisted Matrix Laboratories.
# See LICENSE for details.

"""I am a simple test resource.
"""
import os.path
import cgi as pycgi

from twisted.web2 import log, iweb
from twisted.web2 import static, wsgi, resource, responsecode, twcgi
from twisted.web2 import resource, stream, http, http_headers
from twisted.internet import reactor

class CSS(resource.Resource):
    def render(self, req):
        # This simulates what happens if the file was unchanged
        # It generates the traceback
        return http.Response(
            304,
            {'content-type': http_headers.MimeType('text', 'css')},
            None)
        # This has a valid stream. We don't get a traceback
        return http.Response(
            304,
            {'content-type': http_headers.MimeType('text', 'css')},
            '')
        # This shows what would be returned if the file is changed 
        return http.Response(
            responsecode.OK,
            {'content-type': http_headers.MimeType('text', 'css')},
            'h1 {font-size: 10pt}')

class Toplevel(resource.Resource):
    addSlash=True

    def render(self, req):
        contents = """<html>
<head><title>Twisted.web2 demo server</title>
<link rel="stylesheet" type="text/css" href="mycss"/>
</head>
<body>

<h1>Hello!</h1>  This is a twisted.web2 demo.
</body>
</html>"""

        return http.Response(
            responsecode.OK,
            {'content-type': http_headers.MimeType('text', 'html')},
            contents)

    
    child_mycss = static.File('./schedcss')
    #child_mycss = CSS()

if __name__ == '__builtin__':
    from twisted.application import service, strports
    from twisted.web2 import server, vhost, channel

    test = Toplevel()

    # Setup default common access logging
    res = log.LogWrapperResource(test)
    log.DefaultCommonAccessLoggingObserver().start()

    # Create the site and application objects
    site = server.Site(res)
    application = service.Application("demo")
    
    # Serve it via standard HTTP on port 8080
    s = strports.service('tcp:8080', channel.HTTPFactory(site))
    s.setServiceParent(application)

Traceback:
2006/04/02 20:35 CEST [-] twistd 2.2.0 (/usr/bin/python2.3 2.3.5) starting up
...
2006/04/02 20:40 CEST [HTTPChannel,0,127.0.0.1] Traceback (most recent call last):
          File "/usr/lib/python2.3/site-packages/twisted/internet/defer.py", line 307, in _runCallbacks
            self.result = callback(self.result, *args, **kw)
          File "/usr/lib/python2.3/site-packages/twisted/web2/server.py", line 373, in _cbFinishRender
            d.callback(response)
          File "/usr/lib/python2.3/site-packages/twisted/internet/defer.py", line 229, in callback
            self._startRunCallbacks(result)
          File "/usr/lib/python2.3/site-packages/twisted/internet/defer.py", line 294, in _startRunCallbacks
            self._runCallbacks()
        --- <exception caught here> ---
          File "/usr/lib/python2.3/site-packages/twisted/internet/defer.py", line 307, in _runCallbacks
            self.result = callback(self.result, *args, **kw)
          File "/usr/lib/python2.3/site-packages/twisted/web2/http.py", line 415, in writeResponse
            response.stream.close()
          File "/usr/lib/python2.3/site-packages/twisted/web2/log.py", line 42, in close
            self.stream.close()
        exceptions.AttributeError: 'NoneType' object has no attribute 'close'

Change History (5)

comment:1 Changed 12 years ago by jacob

Type: enhancementdefect

comment:2 Changed 12 years ago by Jean-Paul Calderone

Description: modified (diff)

comment:3 Changed 11 years ago by Glyph

Milestone: Web2-Gold-Master

comment:4 Changed 11 years ago by jknight

Resolution: duplicate
Status: newclosed

Duplicate of the (now fixed) bug #1437.

comment:5 Changed 7 years ago by <automation>

Owner: jknight deleted
Note: See TracTickets for help on using tickets.