[Twisted-Python] Regarding Twisted Matrix

Valeriy Pogrebitskiy vpogrebi at verizon.net
Tue Oct 27 10:49:57 EDT 2009



Using threads - is not a good way of testing Twisted code. Instead, you can
implement unit test script (using twisted.trial.unittest) - 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.) - 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) - thus allowing
you to test client's or server's behavior, or track progress


Kind regards,


Valeriy Pogrebitskiy

Email: vpogrebi at iname.com



-----Original Message-----
From: twisted-python-bounces at twistedmatrix.com
[mailto:twisted-python-bounces at twistedmatrix.com] On Behalf Of naman jain
Sent: Tuesday, October 27, 2009 1:45 AM
To: twisted-python at twistedmatrix.com
Subject: [Twisted-Python] Regarding Twisted Matrix



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)
I want to track the progress of the thread, and send the progress to the
client back

So, I write something like this in my server:

parent_conn, child_conn = Pipe()
thread = Process(target = start_test.main_func, args=(SCRIPT_PATH,
TEMP_OUTPUT_PATH, self.output_name, child_conn))

response = parent_conn.recv()
print response //prints like: initialization done

response = parent_conn.recv()
print response // configuration done


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 "initialization doneconfiguration
thereby defeating the purpose of creating a thread.

How do I give the control to the reactor to write the data back, and still
keep the thread running?
or is there any other way these kinda of progress can be tracked ?
I am kinda stuck with this :(

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://twistedmatrix.com/pipermail/twisted-python/attachments/20091027/ebc6eede/attachment.htm 

More information about the Twisted-Python mailing list