[Twisted-web] Lingering HTTP Channel in web2 when testing with trial

Henrik Thostrup Jensen thostrup at gmail.com
Mon Mar 13 04:16:00 CST 2006


Hi

I have an application which uses web2. In good twisted style I'm writing
tests for it, and using trial.

When performing some rather simple page retrievals a get a lingering http
channel. Setting
twisted.internet.base.DelayedCall.debug = True
I get this trace:


  File "/usr/lib/python2.4/site-packages/twisted/trial/util.py", line 131,
in _dispatch
    getattr(self, "do_%s" % attr)()
  File "/usr/lib/python2.4/site-packages/twisted/trial/util.py", line 173,
in do_cleanPending
    raise PendingTimedCallsError(s)
twisted.trial.util.PendingTimedCallsError: pendingTimedCalls still pending
(consider setting twisted.internet.base.DelayedCall.debug = True):
<DelayedCall 1083946540 [19.9427890778s] called=0 cancelled=0
HTTPChannel._lingerClose()

traceback at creation:

  File "/usr/bin/trial", line 24, in ?
    run()
      File "/usr/lib/python2.4/site-packages/twisted/scripts/trial.py", line
676, in run
    suite = reallyRun(config)
      File "/usr/lib/python2.4/site-packages/twisted/scripts/trial.py", line
657, in reallyRun
    suite.run(config['random'])
      File "/usr/lib/python2.4/site-packages/twisted/trial/runner.py", line
250, in run
    tr.runTests(randomize=(seed is not None))
      File "/usr/lib/python2.4/site-packages/twisted/trial/runner.py", line
496, in runTests
    runner.runTests(randomize)
      File "/usr/lib/python2.4/site-packages/twisted/trial/runner.py", line
601, in runTests
    self._apply(_runTestMethod)
      File "/usr/lib/python2.4/site-packages/twisted/trial/runner.py", line
543, in _apply
    f(tm)
      File "/usr/lib/python2.4/site-packages/twisted/trial/runner.py", line
597, in _runTestMethod
    testMethod.run(tci)
      File "/usr/lib/python2.4/site-packages/twisted/trial/runner.py", line
849, in run
    orig(tci)
      File "/usr/lib/python2.4/site-packages/twisted/trial/runner.py", line
332, in __call__
    lambda :util.wait(defer.maybeDeferred(self.original, *a, **kw),
      File "/usr/lib/python2.4/site-packages/twisted/trial/runner.py", line
409, in _runWithWarningFilters
    return f(*a, **kw)
      File "/usr/lib/python2.4/site-packages/twisted/trial/runner.py", line
333, in <lambda>
    timeout, useWaitError=True))
      File "/usr/lib/python2.4/site-packages/twisted/trial/util.py", line
325, in wait
    r = _Wait.wait(d, timeout)
      File "/usr/lib/python2.4/site-packages/twisted/trial/util.py", line
269, in wait
    reactor.iterate(0.01)
      File "/usr/lib/python2.4/site-packages/twisted/internet/base.py", line
360, in iterate
    self.doIteration(delay)
      File
"/usr/lib/python2.4/site-packages/twisted/internet/selectreactor.py", line
133, in doSelect
    _logrun(selectable, _drdw, selectable, method, dict)
      File "/usr/lib/python2.4/site-packages/twisted/python/log.py", line
56, in callWithLogger
    return callWithContext({"system": lp}, func, *args, **kw)
      File "/usr/lib/python2.4/site-packages/twisted/python/log.py", line
41, in callWithContext
    return context.call({ILogContext: newCtx}, func, *args, **kw)
      File "/usr/lib/python2.4/site-packages/twisted/python/context.py",
line 52, in callWithContext
    return self.currentContext().callWithContext(ctx, func, *args, **kw)
      File "/usr/lib/python2.4/site-packages/twisted/python/context.py",
line 31, in callWithContext
    return func(*args,**kw)
      File
"/usr/lib/python2.4/site-packages/twisted/internet/selectreactor.py", line
139, in _doReadOrWrite
    why = getattr(selectable, method)()
      File "/usr/lib/python2.4/site-packages/twisted/internet/abstract.py",
line 134, in doWrite
    result = self._closeWriteConnection()
      File "/usr/lib/python2.4/site-packages/twisted/internet/tcp.py", line
376, in _closeWriteConnection
    p.writeConnectionLost()
      File "/usr/lib/python2.4/site-packages/twisted/web2/channel/http.py",
line 788, in writeConnectionLost
    self._lingerTimer = reactor.callLater(20, self._lingerClose)
>

This if course makes sense, especially if the server lost its connection. I
am doing cleanup in tearDown (calling stopListening() on the port), but
trial still complains. Canceling the call, and calling it manually in
tearDown, doesn't appear to help either. How do I make it shut it up in a
proper way?


PS. I'm rather pleased with the web2 framework, especially the stream
framework (once I got my head wrapped around it), but it is hard to get an
overview of the internals. A brief description of the design, philosophy,
what was wrong with web(1), etc. would be very nice (I do realize that web2
is a moving target).

--
   - Henrik
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://twistedmatrix.com/pipermail/twisted-web/attachments/20060313/16680bea/attachment.htm


More information about the Twisted-web mailing list