twisted

Is it possible to use tornado's gen.engine and gen.Task with twisted?

此生再无相见时 提交于 2019-12-04 04:46:16
问题 The project I am working on is all written in Tornado, but I have included a bit of Twisted to deal with asynchronous XML-RPC. I was wondering if you can use Tornado's gen.engine and yield gen.Task with Twisted's code. Is this possible? If so how would the syntax look like? Thanks in advance. 回答1: Sure - but it's called inlineCallbacks in Twisted: from twisted.internet.defer import inlineCallbacks @inlineCallbacks def foo(): x = yield bar() print x 回答2: You can use gen.Task with anything that

How to pass extra arguments to callback register functions with twisted python api?

冷暖自知 提交于 2019-12-04 03:54:39
I have the following python code using the twisted API. def function(self,filename): def results(result): //do something for i in range(int(numbers)) : name = something that has to do with the value of i df = function_which_returns_a defer(name) df.addCallback(results) It uses the Twisted API. What i want to achieve is to pass to the callbacked function (results) the value of the name which is constructed in every iteration without changing the content of the functions_which_returns_a defer() function along with the deferred object of course. In every result of the functions_which_returns_a

Running twistd as root, modules aren't found

筅森魡賤 提交于 2019-12-04 03:38:28
问题 I have a simple web server written in Twisted, and I'm trying to start it up daemonized with twistd . Everything works fine with reactor.run() but when I use twistd -y (as root), none of my packages which are in direct child directories get found. I'm running twistd as root, since the server runs on port 80. The manpage for twistd says: Note that if twistd is run as root, the working directory is not searched for Python modules. Well that's great but why? And how can I work around? twistd

Which way to go with twisted and web-programming?

这一生的挚爱 提交于 2019-12-04 03:33:41
So, I programmed this twisted application a few months ago, which I now would like to extend with a web-based user interface for configuration. The Twisted website recommends Nevow, but I am not really sure if this is a good choice. Their website is down for a while it seems and their launchpad page hadn't seen any update in half a year. Is this project dead? Additionally I have seen discussion of moving parts of Nevow into twisted.web on the twisted-web mailinglist. So, is it still recommended for new developments? Another idea was using Django. I would need user authentication and

How to combine callLater and addCallback?

倾然丶 夕夏残阳落幕 提交于 2019-12-04 02:18:36
This is so broken, I hope you are merciful with me: reactor.callLater(0, myFunction, parameter1).addCallback(reactor.stop) reactor.run() myFunction returns a deferred. I hope it is clear what I want to do: as soon as the reactor is running, I want to call myFunction . That is why I am using 0 as the delay parameter. Is there no other way except callLater? It looks funny to pass it a delay of 0. I want to stop the reactor as soon as myFunction has completed the task. The problems that I have so far: AttributeError: DelayedCall instance has no attribute 'addCallback' . Fair enough! How do I put

Good Python networking libraries for building a TCP server?

眉间皱痕 提交于 2019-12-04 01:59:43
I was just wondering what network libraries there are out there for Python for building a TCP/IP server. I know that Twisted might jump to mind but the documentation seems scarce, sloppy, and scattered to me. Also, would using Twisted even have a benefit over rolling my own server with select.select()? I must agree that the documentation is a bit terse but the tutorial gets you up and running quickly. http://twistedmatrix.com/projects/core/documentation/howto/tutorial/index.html The event-based programming paradigm of Twisted and it's defereds might be a bit weird at the start (was for me) but

Autobahn sending user specific and broadcast messages from external application

无人久伴 提交于 2019-12-04 00:55:44
Totally new to websockets. I am having a bit of trouble understanding how to interact with python Autobahn / twisted from another application and cannot seem to find any useful examples. I have a Python application running that needs on certain events to send one of two types of messages. The first is a broadcast message to all users. The second type is to a single specific user. Using the following two examples I can receive messages and send a response. However I do not need to receive anything from connected clients (other than clients connecting to the websockets server) only send to them.

Twisted and Websockets: Beyond Echo

你说的曾经没有我的故事 提交于 2019-12-04 00:26:24
问题 In my ongoing curiosity about websockets, I'm noticing a trend: The "hello world" of the websocket universe, at least at the moment, seems to be "echo" functionality. That is, the demonstrated application is typically, "I send something, I receive something." While aptly demonstrating that the protocol is functional, this example only actually demonstrates the same type of communication that the traditional request / response cycle enables. For example, the only demonstration (on the server

Can writing to a UDP socket ever block?

大兔子大兔子 提交于 2019-12-03 23:57:10
And if so, under what conditions? Or, phrased alternately, is it safe to run this code inside of twisted: class StatsdClient(AbstractStatsdClient): def __init__(self, host, port): super(StatsdClient, self).__init__() self.addr = (host, port) self.server_hostname = socket.gethostname() self.udp_sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) def incr(self, stat, amount=1): data = {"%s|c" % stat: amount} self._send(data) def _send(self, data): for stat, value in data.iteritems(): self.udp_sock.sendto("servers.%s.%s:%s" % (self.server_hostname, stat, value), self.addr) Yes, oddly, a UDP

Running Scrapy on PyPy

淺唱寂寞╮ 提交于 2019-12-03 20:39:54
Is it possible to run Scrapy on PyPy ? I've looked through the documentation and the github project, but the only place where PyPy is mentioned is that there were some unit tests being executed on PyPy 2 years ago, see PyPy support . There is also Scrapy fails in PyPy long discussion happened 3 years ago without a concrete resolution or a follow-up. From what I understand, the main Scrapy's dependency Twisted is known to work on PyPy . Scrapy also uses lxml for HTML parsing, which has a PyPy -friendly fork . The other dependency, pyOpenSSL is fully supported (thanks to @Glyph's comment). Yes.