twisted

sending data between server and client in twisted

I'm trying to transport data between server and client implemented with twisted. As far as I know, using self.transport.write([data]) will work only if data is a string. Is there any other way I can send an object of other type? Thank you! ...

How can Twisted Deferred errors without errbacks be tested with trial?

I have some Twisted code which creates multiple chains of Deferreds. Some of these may fail without having an errback which puts them back on the callback chain. I haven't been able to write a unit test for this code - the failing Deferred causes the test to fail after the test code has completed. How can I write a passing unit test f...

Python twisted asynchronous write using deferred

With regard to the Python Twisted framework, can someone explain to me how to write asynchronously a very large data string to a consumer, say the protocol.transport object? I think what I am missing is a write(data_chunk) function that returns a Deferred. This is what I would like to do: data_block = get_lots_and_lots_data() CHUNK_SI...

Run a function each tick in Twisted

I'm using the twisted framework, and I need to keep track of how much time has passed since an event has started, and perform an action when a certain amount has passed. The best way to do that seems to me to be to check against a time-stamp each tick of the reactor. If it is the best way, how do I do it? If it isn't, what's a better w...

twisted callback function confusion

I'm working on a twisted tutorial just to learn more python and it seems I've ran into a road block here. The doRead() function below is the "callback" of a reactor. What I can't understand is how the except part works. The way I read the code is that if bytes += self.sock.recv(1024) would've caused a block then it will reach the follo...

How to write a twisted server that is also a client?

Hello, How do I create a twisted server that's also a client? I want the reactor to listen while at the same time it can also be use to connect to the same server instance which can also connect and listen. ...

Twisted and enabling command line history

In a previous question of mine i get this answer: Subclass twisted.conch.recvline.HistoricRecvLine instead of twisted.protocols.basic.LineReceiver. keystrokeReceived is one of the several additional protocol callbacks available when you are using a terminal instead of a TCP connection. – Jean-Paul Calderone Which is fine. But what if w...

Good tutorial/example of SFTP server in Twisted Conch?

Hi, can anyone recommend a good example or tutorial of how to add SFTP capabilities to a Twisted Conch SSH server? Is it possible to run an Conch SFTP server that I can connect to using other SFTP clients? I'm just getting started with Twisted. Thanks. ...

Twisted and command line history console application

So i did the following (This app is a client and a server at the same time) class WebCheckerCommandProtocol(recvline.HistoricRecvLine): def connectionMade(self): self.sendLine("checker console. Type 'help' for help.") def lineReceived(self, line): ... def connectionLost(self, reason): # stop the re...

Generate headers in Twisted client

Hi All, i'm using the Twisted web "HTTPClient" protocol to dialogue with a http server (using twisted app as a client), the problem is that most of my request do not accept my header. Is there some sort of way (maybe using certain libraries) to generate header?? I'll post some code so you can have a look class Local(HTTPClient): def gen...

Python twisted: how to schedule?

Hi, all! Having 1-day experience in Twisted I try to schedule message sending in reply to tcp client: import os, sys, time from twisted.internet import protocol, reactor self.scenario = [(1, "Message after 1 sec!"), (4, "This after 4 secs"), (2, "End final after 2 secs")] for timeout, data in self.scenario: reactor.callLater(ti...

Use my own main loop in twisted

I have an existing program that has its own main loop, and does computations based on input it receives - let's say from the user, to make it simple. I want to now do the computations remotely instead of locally, and I decided to implement the RPCs in Twisted. Ideally I just want to change one of my functions, say doComputation(), to m...

in Twisted, wait until connection closed cleanly

I want to disconnect cleanly, and then stop the reactor. If I do this, however: controller.connection.disconnect() reactor.stop() then I get a "connection was lost in a non-clean fashion" message. If I insert a time.sleep(1) in between them, the connection closes cleanly. How can I wait until the connection is really closed? ...

twisted, unblock a threads.blockingCallFromThread when the reactor stops

it seems threads.blockingCallFromThread keeps blocking even when the reactor stops. is there any way to un-block it? the deferred that it is blocking on relies on an RPC coming from the other end, and that definitely won't come in with the reactor stopped. ...

twisted.protocols.ftp.FTPClient and Deferreds

Like most it's taking me a while to get used to using Deferreds but I'm slowly getting there. However, it's not clear to me how I can process a response and then call another FTP command using the processed response when using Twisted's FTP module. I'm using the the example FTP code as my jumping off point. I want to connect to a FTP se...

getting result from a function running "deferToThread"

Hi, I have recently started working on twisted not much familiar with its functions.I have a problem related to "deferToThread" method...my code is here to use this method from twisted.internet.threads import deferToThread from twisted.internet import reactor results=[] class Tool(object): def exectool(self,tool): # print "Te...

How to use twisted for downloading a remote file?

I'm relatively new to twisted and I'm planning on using it to create a file downloader. It would accept a file url and a number of parts to download the file. What I have in mind is to split the file into how many parts the user specified and download each parts through deferred and when it is done, all parts gets assembled. But do I n...

How to create partial download in twisted?

How do you create multiple HTTPDownloader instance with partial download asynchronously? and does it assemble the file automatically after all download is done? ...

Limit connection rate in Python Twisted?

Is there any way to limit connection rate in Python Twisted? I need to simulate the slow dataline, with timeouts and optionally data loss and use twisted framework. ...

twisted: check whether a deferred has already been called

This is what I'm trying to accomplish. I'm making a remote call to a server for information, and I want to block to wait for the info. I created a function that returns a Deferred such that when the RPC comes in with the reply, the deferred is called. Then I have a function called from a thread that goes threads.blockingCallFromThread(re...