I tried to implement this:<br><br>parent_conn, child_conn = Pipe()<br><br>f = defer.Deferred()<br>f = threads.deferToThread(start_test.main_func, SCRIPT_PATH, TEMP_OUTPUT_PATH, self.output_name, child_conn)<br><br>response = parent_conn.recv()<br>
print response //prints like: initialization done<br>
self.transport.write(response)<br>
<br>response = parent_conn.recv()<br>
print response // configuration done<br>
self.transport.write(response)<br><br>But get the same output ie all status messages concatenated and sent at once.!<br><br>[Do we need to put some deffered/callback mechanism on parent_conn.recv() ??<br>as that is the call blocking the thread waiting for reading.]<br>
<br>Any ideas ? How is such stuff done in twisted servers??<br><br>Naman<br><br><br><div class="gmail_quote">On Tue, Oct 27, 2009 at 7:03 AM, Nathan <span dir="ltr"><<a href="mailto:nathan.stocks@gmail.com">nathan.stocks@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><div><div></div><div class="h5">On Mon, Oct 26, 2009 at 11:44 PM, naman jain <<a href="mailto:namanvit@gmail.com">namanvit@gmail.com</a>> wrote:<br>
> Hi,<br>
><br>
> I have a client server model in twisted, where the server spawns a thread (<br>
> basically a test script in python that runs for about 20 mins)<br>
> I want to track the progress of the thread, and send the progress to the<br>
> client back<br>
><br>
> So, I write something like this in my server:<br>
><br>
> parent_conn, child_conn = Pipe()<br>
> thread = Process(target = start_test.main_func, args=(SCRIPT_PATH,<br>
> TEMP_OUTPUT_PATH, self.output_name, child_conn))<br>
> thread.start()<br>
><br>
> response = parent_conn.recv()<br>
> print response //prints like: initialization done<br>
> self.transport.write(response)<br>
><br>
><br>
> response = parent_conn.recv()<br>
> print response // configuration done<br>
> self.transport.write(response)<br>
><br>
> .<br>
> .<br>
> .<br>
><br>
> thread.join()<br>
><br>
><br>
> But the transport.write calls don't send at the same time. instead they wait<br>
> for the thread to finish (coz of thread.join) and then append all the<br>
> response and send it back; like "initialization doneconfiguration<br>
> done...done"<br>
> thereby defeating the purpose of creating a thread.<br>
><br>
> How do I give the control to the reactor to write the data back, and still<br>
> keep the thread running?<br>
> or is there any other way these kinda of progress can be tracked ?<br>
> I am kinda stuck with this :(<br>
<br>
</div></div>I'm no expert with threads, but I don't see any deferToThread in<br>
there, which is what people on this list tend to mention whenever<br>
threading comes up. Perhaps you need to switch to the "twisted way"<br>
to create your thread?<br>
<br>
<a href="http://twistedmatrix.com/documents/8.2.0/api/twisted.internet.threads.html" target="_blank">http://twistedmatrix.com/documents/8.2.0/api/twisted.internet.threads.html</a><br>
<font color="#888888"><br>
~ Nathan<br>
</font><div><div></div><div class="h5"><br>
_______________________________________________<br>
Twisted-Python mailing list<br>
<a href="mailto:Twisted-Python@twistedmatrix.com">Twisted-Python@twistedmatrix.com</a><br>
<a href="http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python" target="_blank">http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python</a><br>
</div></div></blockquote></div><br>