[Twisted-Python] getProcessOutput - Can it be made to return 'output' instead of differed
exarkun at twistedmatrix.com
exarkun at twistedmatrix.com
Tue Sep 28 08:51:22 EDT 2010
On 10:16 am, orsenthil at gmail.com wrote:
>Hello,
>
>My current application structure is like this:
>
>If something:
> d = defertoThread(func1,params1)
>if something2:
> d = defertoThread(func2, params2)
>...
>
>
>d.addCallback(lambda r: transport.write(r)
>
>I had designed it this way because, the functions, func1, func2 etc..
>were all assumed to be Blocking ones.
>One of them, internally uses subprocess.Popen() and executes the
>command and returns the output. All is fine till now.
>
>But I had situation, where for the process which is executed via
>subprocess module, I had to attach a pseudo-terminal.
>subprocess does not have a mechanism to send a pseudo-terminal to the
>process.
>
>So, I looked into utils.getProcessOutput and found that it does have a
>mechanism to send a psuedo-terminal to the process.
>But the problem I am facing is, if I replace the subprocess Call in
>one of those functions (which are called via deferToThread ), I might
>need to return the value (in a blocking way) so that it fits in rest
>of the program well.
>
>
>So, my question is, how can I make utils.getProcessOutput return value
>instead of a differed. I am okay if it blocks.
It's "Deferred" not "differed". You cannot make getProcessOutput return
anything but a Deferred. Also, you cannot call getProcessOutput from a
thread.
If you're removing the code that blocks, then you should be able to stop
using deferToThread. Then you just have to call getProcessOutput to get
your `d` above (or another function that calls it and perhaps adds a
callback or two).
Jean-Paul
More information about the Twisted-Python
mailing list