twisted

Twisted - sending data to selected clients

淺唱寂寞╮ 提交于 2019-11-29 23:00:49
问题 There is this server I made with Twisted which receives strings from a client and send it to all of the other connected clients. But is there a way to send the string to just clients that the sender wanted to send it to ? If so, how do I do it in code ? This is what I did so far (NOTE I am a complete noob in Python. I just need to build a server for my iOS app, so I am sorry if the question is silly): from twisted.internet.protocol import Protocol, Factory from twisted.internet import reactor

How to get the client IP address after got connection lost in twisted

こ雲淡風輕ζ 提交于 2019-11-29 22:52:10
问题 I know we can get the client (host) IP after connection has been established because at that time we will have transport attribute: self.transport.getPeer() but how do I get the IP address of the client in twisted TCP server when it lost connection to the server, as in after it got disconnected. 回答1: Its a little late for that. I suggest you save this information when you have it. For example: class YourProtocol(protocol.Protocol): def connectionMade(self): self._peer = self.transport.getPeer

Twisted: Waiting for subtasks to finish

删除回忆录丶 提交于 2019-11-29 21:48:39
问题 In my code, I have two hypothetical tasks: one gets urls from a generator and batch downloads them using Twisted's Cooperator, and the other takes a downloaded source and asynchronously parses it. I'm trying to encapsulate all of the fetch and parse tasks into a single Deferred object that calls back when all pages are downloaded and all sources are parsed. I've come up with the following solution: from twisted.internet import defer, task, reactor, threads from twisted.web.client import

Use my own main loop in twisted

不想你离开。 提交于 2019-11-29 21:26:11
问题 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 make a call to twisted to perform the RPC, get the results, and return. The rest of the program should stay the same. How can I accomplish this, though? Twisted

How do I write a setup.py for a twistd/twisted plugin that works with setuptools, distribute, etc?

試著忘記壹切 提交于 2019-11-29 20:27:42
The Twisted Plugin System is the preferred way to write extensible twisted applications. However, due to the way the plugin system is structured (plugins go into a twisted/plugins directory which should not be a Python package), writing a proper setup.py for installing those plugins appears to be non-trivial. I've seen some attempts that add 'twisted.plugins' to the 'packages' key of the distutils setup command, but since it is not really a package, bad things happen (for example, an __init__.py is helpfully added by some tools). Other attempts seem to use 'package_data' instead (eg, http:/

python安装scrapy/Twisted遇见的坑

陌路散爱 提交于 2019-11-29 18:55:02
入门python,一直听闻有一款非常出门的爬虫框架scrapy,非常想尝试一下,于是通过pip install安装,无奈各种报错(的确是各种报错!!),因为scrapy主要依赖的几个库并不支持python3.x。最后经过我不懈的努力,终于通过各种途径在win10 64位 python3.6的环境下成功安装scrapy。当然,如果经不起折腾通过python2.7安装是最简单的,在这里请允许我吐槽一下python的版本兼容性,已经被不止坑了一次了!下面大概介绍遇见的几个大坑,及解决方法: lxml等包安装报错,这些可以通过去pip官网下载whl然后本地安装就可以解决,网上的讨论很多也很有效就不多提 twisted安装异常,这个是最坑的,我尝试了很久才解决。首先,twisted不支持python3.x,所以通过官方途径下载的包可以歇了。我找了一些攻略,终于活捉到改版后的野生twisted,链接 https://pan.baidu.com/s/1sle2CmL?errno=0&errmsg=Auth%20Login%20Sucess&&bduss=&ssnerror=0&traceid=#list/path=%2FPython%2Ftwisted-for-python3&parentPath=%2FPython 按照自己系统版本下载安装,安装完成后可以通过命令行测试一下(如果链接失效

What's meaning of these formats in twisted's docstring?

梦想与她 提交于 2019-11-29 18:50:14
问题 In twisted's sourcecode, many docstrings contain formats like this: L{xxx} or C{xxx} or a line begin with an '@', what's their meanings? for example, in twisted/internet/interfaces.py: def registerProducer(producer, streaming): """ Register to receive data from a producer. ... For L{IPullProducer} providers, C{resumeProducing} will be called once each time data is required. ... @type producer: L{IProducer} provider ... @return: C{None} """ L{IPullProducer} , C{resumeProducing} , @type

When to use Tornado, when to use Twisted / Cyclone / GEvent / other [closed]

天大地大妈咪最大 提交于 2019-11-29 18:31:11
Which of these frameworks / libraries would be the best choise for building modern multiuser web application? I would love to have an asynchronous webserver which will allow me to scale easly. What solution will give the best performance / scalability / most useful framework (in terms of easy of use and easy of developing)? It would be great if it will provide good functionality (websockets, rpc, streaming, etc). What are the pros and cons of each solution? " Django is a high-level Python Web framework that encourages rapid development and clean, pragmatic design" . If you are building

Python DeferredList callback reporting success when deferreds raise error

匆匆过客 提交于 2019-11-29 17:28:08
I have the following simple script: #!/usr/bin/env python from twisted.internet import defer from twisted.web.client import getPage, reactor def success(results): print 'success' def error(results): print 'error' def finished(results): print 'finished', results tasks = [] d = getPage('thiswontwork').addCallback(success).addErrback(error) tasks.append(d) dl = defer.DeferredList(tasks) dl.addCallback(finished) reactor.run() That produces the following output: error finished [(True, None)] I would expect this error task to return a false since the getPages task fails and calls it's error callback

How does Python's Twisted Reactor work?

巧了我就是萌 提交于 2019-11-29 16:31:54
问题 Recently, I've been diving into the Twisted docs. From what I gathered, the basis of Twisted's functionality is the result of it's event loop called the "Reactor". The reactor listens for certain events and dispatches them to registered callback functions that have been designed to handle these events. In the book, there is some pseudo code describing what the Reactor does but I'm having trouble understanding it, it just doesn't make any sense to me. while True: timeout = time_until_next