Re: [Twisted-Python] Re: A Python metaclass for Twisted allowing __init__ to return a Deferred

2008-12-06 Thread Terry Jones
Hi Nicola!

> "Nicola" == Nicola Larosa <[EMAIL PROTECTED]> writes:
Nicola> Terry Jones wrote:
>> BTW, I spent an interesting morning getting my head around *exactly* how
>> inlineCallbacks does its thing... No summary of my thoughts could do it
>> justice. I wonder how many people on the planet have been down that
>> rabbit hole.

Nicola> Not me, man, not me. I just use the bloody thing, and curse it when
Nicola> it shortens tracebacks.

I know exactly what you're talking about, and I hated that too. But I dug
into that and found out where the problem was: I didn't know Python well
enough :-)

I bet you're doing something like this:

@inlineCallbacks
def f():
# Whatever
try:
# Your code here
except Exception, e:
# Do some cleaning up, maybe write to the log, maybe call another
# function that uses inlineCallbacks
raise e

or just

@inlineCallbacks
def f():
# Whatever
try:
# Your code here
except Exception:
# Do some cleaning up, maybe write to the log, maybe call another
# function that uses inlineCallbacks
raise


The problem here is that you're not using the 3-argument form of raise. So
you're either dropping information (with the raise e) or pulling out the
last exception (with the no-arg raise).

Consider the latter case. Suppose your cleanup code calls another function
that uses inlineCallbacks. That function will eventually raise
StopIteration or raise via calling defer.returnValue. So by the time
control returns to your code, your raise (which implicitly uses
sys.exc_info()) raises the wrong exception! So you get e.g., a
StopIteration exception coming at you out of your inlineCallbacks function
and you curse the thing :-) This applies if your cleanup code calls any
iterator, or if you call something that try/except catches a KeyError, etc.

So just use

@inlineCallbacks
def f():
# Whatever
try:
# Your code here
except Exception:
info = sys.exc_info()
# Do some cleaning up, maybe write to the log, maybe call another
# function that uses inlineCallbacks
raise info[0], info[1], info[2]

and it just works. Try it :-) You cant do anything nice like raise *info
because Python's parser doesn't like that (AFAIR).

I nearly posted about this to the list, but I figured it might help if I
had more of a clue about Python itself, seeing as what I was doing was
nothing to do with Twisted.


>> I hope people don't mind my peanut gallery commentary. We're all in this
>> together, after all. A little gallows humor occasionally seems in order.
Nicola> Again, certainly not me. Go right ahead! ;-)

Don't encourage me...

Terry

___
Twisted-Python mailing list
Twisted-Python@twistedmatrix.com
http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python


[Twisted-Python] Weekly Bug Summary

2008-12-06 Thread exarkun



Bug summary
__
Summary for 2008-11-30 through 2008-12-07
Bugs opened: 11Bugs closed: 7  Total open bugs: 1056 (+4)

|== Type Changes   |== Priority Changes   |== Component Changes   
|Defect:   +0  |Highest:  +2  |Core: +2   
|Enhancement:  +1  |High: -1  |Lore: +2   
|Task: +3  |Normal:   +3  |Mail: +1   
   |Low:  +0  |Trial:-1   
  |Web:  +1   
  |Website:  -1   



Total Tickets
Open Tickets



New / Reopened Bugs
__
= Highest =
[#3559] remove woven usage from twisted.web.distrib (opened by exarkun)
taskwebhttp://twistedmatrix.com/trac/ticket/3559

[#3561] deprecate microdom (opened by exarkun)
taskwebhttp://twistedmatrix.com/trac/ticket/3561

= Normal =
[#3560] remove usage of microdom from twisted.lore (opened by exarkun)
enhancement lore   http://twistedmatrix.com/trac/ticket/3560

[#3562] Setup Python 3.0 buildslave(s) (opened by thijs)
taskcore   http://twistedmatrix.com/trac/ticket/3562

[#3563] Setup Python 2.6 windows buildslave (opened by thijs) (CLOSED, fixed)
taskcore   http://twistedmatrix.com/trac/ticket/3563

[#3564] twisted.test.test_persisted.EphemeralTestCase.testEphemeral failing when there is no gc.get_referrers (opened by fijal) (CLOSED, fixed)
defect  core   http://twistedmatrix.com/trac/ticket/3564

[#3565] Lore does not close files (opened by fijal)
defect  lore   http://twistedmatrix.com/trac/ticket/3565

[#3566] pb test_logoutAfterDecref relies on reference count semantics (opened by exarkun)
defect  core   http://twistedmatrix.com/trac/ticket/3566

[#3567] Windows spawnProcess uses invalid open mode "u" (opened by exarkun)
defect  core   http://twistedmatrix.com/trac/ticket/3567

[#414 ] Lore incorrectly throws away text nodes which are all whitespace, omitting them from the output document (opened by Nafai)
defect  lore   http://twistedmatrix.com/trac/ticket/414

= Low =
[#3558] t.m.imap4.IMessagePart should allow providers to control the order of headers and provide multiple instances of particular headers (opened by ebroder)
enhancement mail   http://twistedmatrix.com/trac/ticket/3558



Closed Bugs
__
= High =
[#520 ] indentation problem with certain html docs and Safari browser (opened by speno, closed by exarkun, fixed)
defect  websitehttp://twistedmatrix.com/trac/ticket/520

= Normal =
[#414 ] Lore incorrectly throws away text nodes which are all whitespace, omitting them from the output document (opened by Nafai, closed by exarkun, )
defect  lore   http://twistedmatrix.com/trac/ticket/414

[#2993] Document AMP routes (opened by bigdog, closed by glyph, wontfix)
enhancement core   http://twistedmatrix.com/trac/ticket/2993

[#3564] twisted.test.test_persisted.EphemeralTestCase.testEphemeral failing when there is no gc.get_referrers (opened by fijal, closed by exarkun, fixed)
defect  core   http://twistedmatrix.com/trac/ticket/3564

[#3563] Setup Python 2.6 windows buildslave (opened by thijs, closed by exarkun, fixed)
taskcore   http://twistedmatrix.com/trac/ticket/3563

[#1944] trial --coverage makes some tests fail spuriously (opened by washort, closed by exarkun, wontfix)
defect  trial  http://twistedmatrix.com/trac/ticket/1944

= Low =
[#3421] Useless assertion in twisted.web.microdom.Node.replaceChild (opened by exarkun, closed by exarkun, fixed)
defect  webhttp://twistedmatrix.com/trac/ticket/3421



Ticket Lifetime Stats
__
Oldest open ticket - [#49] RFE: enhancements to Lore for --config book (since 2003-07-12 16:39:56).
Newest open ticket - [#3567] Windows spawnProcess uses invalid open mode "u" (since 2008-12-05 16:43:42).

Mean open ticket age: 728 days, 11:35:33.677183.
Median: 664 days, 3:41:08.419608.
Standard deviation: 506 days, 1:44:17.993341.
Interquartile range: 702 days, 22:30:31.

Mean time between ticket creation and ticket resolution: 189 days, 18:55:02.188358.
Median: 26 days, 0:16:43.
Standard deviation is 321 days, 5:16:34.206608.
The interquartile range is 221 days, 2:40:54.

Mean time spent in review: 69 days, 12:31:18.600417.
Median: 3 days, 23:03:09.
Standard deviation: 212 days, 13:56:03.637442.
Interquartile range: 17 days, 11:06:32.

Mean number of times a ticket is reviewed: 2.06531531532.
Median: 1
Standard deviation: 1.69332676445.
Interquartile range: 1.


Contributor St