<html>

<head>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=us-ascii">


<meta name=Generator content="Microsoft Word 10 (filtered)">

<style>
<!--
 /* Font Definitions */
 @font-face
        {font-family:Tahoma;
        panose-1:2 11 6 4 3 5 4 4 2 4;}
 /* Style Definitions */
 p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:"Times New Roman";}
a:link, span.MsoHyperlink
        {color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {color:blue;
        text-decoration:underline;}
span.EmailStyle17
        {font-family:Arial;
        color:navy;}
@page Section1
        {size:8.5in 11.0in;
        margin:1.0in 1.25in 1.0in 1.25in;}
div.Section1
        {page:Section1;}
-->
</style>

</head>

<body lang=EN-US link=blue vlink=blue>

<div class=Section1>

<p class=MsoNormal><font size=2 color=navy face=Arial><span style='font-size:
10.0pt;font-family:Arial;color:navy'>Naman,</span></font></p>

<p class=MsoNormal><font size=2 color=navy face=Arial><span style='font-size:
10.0pt;font-family:Arial;color:navy'>&nbsp;</span></font></p>

<p class=MsoNormal><font size=2 color=navy face=Arial><span style='font-size:
10.0pt;font-family:Arial;color:navy'>Another problem you might (possibly) be
encountering &#8211; is the way your server and/or client protocol is implemented.
If you just inherit from &#8220;plain&#8221; twisted.internet.protocol.Protocol
&#8211; you are automatically using write () and dataReceived() methods that do
not implement buffering (it is left up to developer). To enforce that line
(string) oriented communication works correctly &#8211; you might want to refactor
to use twisted.protocols.basic.LineReceiver instead. </span></font></p>

<p class=MsoNormal><font size=2 color=navy face=Arial><span style='font-size:
10.0pt;font-family:Arial;color:navy'>&nbsp;</span></font></p>

<div>

<p class=MsoNormal><font size=2 color=navy face=Arial><span style='font-size:
10.0pt;font-family:Arial;color:navy'>Kind regards,</span></font></p>

<p class=MsoNormal><font size=3 color=navy face="Times New Roman"><span
style='font-size:12.0pt;color:navy'>&nbsp;</span></font></p>

<p class=MsoNormal><font size=2 color=navy face=Arial><span style='font-size:
10.0pt;font-family:Arial;color:navy'>Valeriy Pogrebitskiy</span></font></p>

<p class=MsoNormal><font size=2 color=navy face=Arial><span style='font-size:
10.0pt;font-family:Arial;color:navy'>Email: <a href="mailto:vpogrebi@iname.com">vpogrebi@iname.com</a></span></font></p>

<p class=MsoNormal><font size=3 color=navy face="Times New Roman"><span
style='font-size:12.0pt;color:navy'>&nbsp;</span></font></p>

<p class=MsoNormal><font size=3 color=navy face="Times New Roman"><span
style='font-size:12.0pt;color:navy'>&nbsp;</span></font></p>

</div>

<p class=MsoNormal style='margin-left:.5in'><font size=2 face=Tahoma><span
style='font-size:10.0pt;font-family:Tahoma'>-----Original Message-----<br>
<b><span style='font-weight:bold'>From:</span></b>
twisted-python-bounces@twistedmatrix.com
[mailto:twisted-python-bounces@twistedmatrix.com] <b><span style='font-weight:
bold'>On Behalf Of </span></b>naman jain<br>
<b><span style='font-weight:bold'>Sent:</span></b> Tuesday, October 27, 2009
6:36 AM<br>
<b><span style='font-weight:bold'>To:</span></b> Twisted general discussion<br>
<b><span style='font-weight:bold'>Subject:</span></b> Re: [Twisted-Python]
Regarding Twisted Matrix</span></font></p>

<p class=MsoNormal style='margin-left:.5in'><font size=3 face="Times New Roman"><span
style='font-size:12.0pt'>&nbsp;</span></font></p>

<p class=MsoNormal style='margin-right:0in;margin-bottom:12.0pt;margin-left:
.5in'><font size=3 face="Times New Roman"><span style='font-size:12.0pt'>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&nbsp; 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>
</span></font></p>

<div>

<p class=MsoNormal style='margin-left:.5in'><font size=3 face="Times New Roman"><span
style='font-size:12.0pt'>On Tue, Oct 27, 2009 at 7:03 AM, Nathan &lt;<a
href="mailto:nathan.stocks@gmail.com">nathan.stocks@gmail.com</a>&gt; wrote:</span></font></p>

<div>

<div>

<p class=MsoNormal style='margin-right:0in;margin-bottom:12.0pt;margin-left:
.5in'><font size=3 face="Times New Roman"><span style='font-size:12.0pt'>On
Mon, Oct 26, 2009 at 11:44 PM, naman jain &lt;<a
href="mailto:namanvit@gmail.com">namanvit@gmail.com</a>&gt; wrote:<br>
&gt; Hi,<br>
&gt;<br>
&gt; I have a client server model in twisted, where the server spawns a thread
(<br>
&gt; basically a test script in python that runs for about 20 mins)<br>
&gt; I want to track the progress of the thread, and send the progress to the<br>
&gt; client back<br>
&gt;<br>
&gt; So, I write something like this in my server:<br>
&gt;<br>
&gt; parent_conn, child_conn = Pipe()<br>
&gt; thread = Process(target = start_test.main_func, args=(SCRIPT_PATH,<br>
&gt; TEMP_OUTPUT_PATH, self.output_name, child_conn))<br>
&gt; thread.start()<br>
&gt;<br>
&gt; response = parent_conn.recv()<br>
&gt; print response //prints like: initialization done<br>
&gt; self.transport.write(response)<br>
&gt;<br>
&gt;<br>
&gt; response = parent_conn.recv()<br>
&gt; print response // configuration done<br>
&gt; self.transport.write(response)<br>
&gt;<br>
&gt; .<br>
&gt; .<br>
&gt; .<br>
&gt;<br>
&gt; thread.join()<br>
&gt;<br>
&gt;<br>
&gt; But the transport.write calls don't send at the same time. instead they
wait<br>
&gt; for the thread to finish (coz of thread.join) and then append all the<br>
&gt; response and send it back; like &quot;initialization doneconfiguration<br>
&gt; done...done&quot;<br>
&gt; thereby defeating the purpose of creating a thread.<br>
&gt;<br>
&gt; How do I give the control to the reactor to write the data back, and still<br>
&gt; keep the thread running?<br>
&gt; or is there any other way these kinda of progress can be tracked ?<br>
&gt; I am kinda stuck with this :(</span></font></p>

</div>

</div>

<p class=MsoNormal style='margin-left:.5in'><font size=3 face="Times New Roman"><span
style='font-size:12.0pt'>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. &nbsp;Perhaps you need to switch to the &quot;twisted
way&quot;<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"><span style='color:#888888'><br>
~ Nathan</span></font></span></font></p>

<div>

<div>

<p class=MsoNormal style='margin-left:.5in'><font size=3 face="Times New Roman"><span
style='font-size:12.0pt'><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></span></font></p>

</div>

</div>

</div>

<p class=MsoNormal style='margin-left:.5in'><font size=3 face="Times New Roman"><span
style='font-size:12.0pt'>&nbsp;</span></font></p>

</div>

</body>

</html>