<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:purple;
        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=purple>

<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'>Using threads &#8211; is not a good way of
testing Twisted code. Instead, you can implement unit test script (using twisted.trial.unittest)
&#8211; implementing test versions of your Twisted server and/or client class(es).
This can be done by extending original class(es) and overwriting appropriate
methods (like connectionMade(), connectionLost(), dataReceived(), etc.) &#8211;
by adding deferreds and executing callbacks when given event occurs. These
callbacks would be methods within your unittest script (these deferreds would
be instantiated and added to these classes by the test script) &#8211; thus allowing
you to test client&#8217;s or server&#8217;s behavior, or track progress</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> </span></font><font size=2 face=Tahoma><span style='font-size:10.0pt;font-family:Tahoma'>Tuesday,
 October 27, 2009</span></font><font size=2 face=Tahoma><span style='font-size:
10.0pt;font-family:Tahoma'> </span></font><font size=2 face=Tahoma><span
 style='font-size:10.0pt;font-family:Tahoma'>1:45 AM</span></font><font size=2
face=Tahoma><span style='font-size:10.0pt;font-family:Tahoma'><br>
<b><span style='font-weight:bold'>To:</span></b>
twisted-python@twistedmatrix.com<br>
<b><span style='font-weight:bold'>Subject:</span></b> [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'>Hi,<br>
<br>
I have a client server model in twisted, where the server spawns a thread (
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 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,
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>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br>
<br>
response = parent_conn.recv()<br>
print response // configuration done<br>
self.transport.write(response)<br>
<br>
.<br>
.<br>
.<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br>
thread.join()<br>
<br>
<br>
But the transport.write calls don't send at the same time. instead they wait
for the thread to finish (coz of thread.join) and then append all the response
and send it back; like &quot;initialization doneconfiguration done...done&quot;<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 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 :(</span></font></p>

</div>

</body>

</html>