[Twisted-Python] getProcessOutput - Can it be made to return 'output' instead of differed
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. http://twistedmatrix.com/trac/browser/tags/releases/twisted-10.1.0/twisted/i... Please let me know if you have any other suggestions. (I am still a learner here). TIA, -- Senthil
On 10:16 am, orsenthil@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
On Tue, Sep 28, 2010 at 12:51:22PM -0000, exarkun@twistedmatrix.com wrote:
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).
Thanks for the response. I could recognize this option, I just thought that structurally it might odd as only one of them is a defer from a process while others will be from thread. But I guess, it does not matter. I shall try this approach. Thanks, Senthil
participants (2)
-
exarkun@twistedmatrix.com
-
Senthil Kumaran