[Twisted-Python] reactor.stop() won't, threads and Queue to blame?

Clark C. Evans cce at clarkevans.com
Mon Oct 25 14:14:14 EDT 2004


On Mon, Oct 25, 2004 at 12:41:12PM -0400, Brett Viren wrote:
| Andrew Bennetts <andrew-twisted at puzzling.org> writes:
| 
| > Yep, that's the problem here.  Change this:
| >     d.callback(meth(*a,**k))
| > to this:
| >     reactor.callFromThread(d.callback, meth(*a, **k))
| >
| > (Or perhaps less confusingly:
| >     result = meth(*a, **kw)
| >     reactor.callFromThread(d.callback, result)
| > )
| 
| Yes, that did it.

If your meth() could raise an exception, you probably also
need to wrap that function call in a try/except block.

    try:
        result = meth(*a, **kw)
    except:
        result = failure.Failure()
    reactor.callFromThread(d.callback, result)

Best,

Clark




More information about the Twisted-Python mailing list