<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'> </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 – is the way your server and/or client protocol is implemented.
If you just inherit from “plain” twisted.internet.protocol.Protocol
– 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 – 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'> </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'> </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'> </span></font></p>
<p class=MsoNormal><font size=3 color=navy face="Times New Roman"><span
style='font-size:12.0pt;color:navy'> </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'> </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 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 <<a
href="mailto:nathan.stocks@gmail.com">nathan.stocks@gmail.com</a>> 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 <<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 :(</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. 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"><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'> </span></font></p>
</div>
</body>
</html>