[Twisted-Python] deferToThread question
Matt Goodall
matt at pollenation.net
Fri Aug 20 05:32:56 EDT 2004
On Fri, 2004-08-20 at 10:07, Michele Petrazzo wrote:
> I want to call a block function. I use deferToThread to call it, so
> something like this:
>
> def block_func():
> os.popen3(my_soft) #my_soft is a blocking software
> print 1/0 # Simulate an error
I can't answer your threading question but Twisted supports async
process execution so you probably don't actually need a thread. See the
HOWTO, http://twistedmatrix.com/documents/current/howto/process, for
more.
>
> If I use normal (not defer) call, so: block_func(), the exception is
> raised after my_soft is closed.
>
> I i call block_func with defer, so:
>
> def block_func_err(err):
> print err
>
> t = threads.deferToThread(block_func)
> t.addErrback(block_func_err)
>
> the error is raised before my_soft is closed.
>
> Why? Is it right?
>
> S.O. win2k and mdk10, both with py 2.3.4, twisted 1.3.0, wxpy 2.4.2 and
> user of wxsupport, not wxreactor.
>
> Thanks,
> Michele Petrazzo
--
Matt Goodall <matt at pollenation.net>
More information about the Twisted-Python
mailing list