twisted

Python: SocketServer closes TCP connection unexpectedly

妖精的绣舞 提交于 2019-11-30 17:51:30
问题 I would like to implement a TCP/IP network client application that sends requests to a Python SocketServer and expects responses in return. I have started out with the official Python SocketServer sample code: server.py: #!/usr/bin/env python # encoding: utf-8 import SocketServer class MyTCPHandler(SocketServer.StreamRequestHandler): def handle(self): request = self.rfile.readline().strip() print "RX [%s]: %s" % (self.client_address[0], request) response = self.processRequest(request) print

Twisted: Creating a ThreadPool and then daemonizing leads to uninformative hangs

允我心安 提交于 2019-11-30 17:13:18
问题 I am developing a networked application in Twisted, part of which consists of a web interface written in Django. I wish to use Twisted's WSGI server to host the web interface, and I've written a working "tap" plugin to allow me to use twistd . When running the server with the -n flag (don't daemonize) everything works fine, but when this flag is removed the server doesn't respond to requests at all, and there are no messages logged (though the server is still running). There is a bug on

Memory leak in Python Twisted: where is it?

风格不统一 提交于 2019-11-30 16:44:20
问题 I have a Twisted server under load. When the server is under load, memory usage increases, and it is never reclaimed (even when there are no more clients). Next time it goes into high load, memory usage increases again. Here's a snapshot of the situation at that point: RSS memory is 400 MB (should be 200MB with usual max number of clients). gc.garbage is empty, so there are no uncollectable objects. Using objgraph.py shows no obvious candidates for leaks (no notable difference between a

(转)Twisted :第一部分:初步认识Twisted

丶灬走出姿态 提交于 2019-11-30 16:41:56
前言 : 最近有人在Twisted邮件列表中提出诸如”为任务紧急的人提供一份Twisted介绍”的的需求。值得提前透露的是,这个序列并不会如他们所愿.尤其是介绍Twisted框架和基于Python 的异步编程而言,可能短时间无法讲清楚。因此,如果你时间紧急,这恐怕不是你想找的资料。 我相信如果对异步编程模型一无所知,快速的介绍同样无法让你对其有所理解,至少你得稍微懂点基础知识吧。我已经用Twisted框架几年了,因此思考过我当初是怎么学习它(学得很慢)并发现学习它的最大难度并不在Twisted本身,而在于对其模型的理解,只有理解了这个模型,你才能更好去写和理解异步程序的代码。大部分Twisted的代码写得很清晰,其在线文档也非常棒(至少在开源软件这个层次上可以这么说)。但如果不理解这个模型,不管是读Twisted源码还是使用Twisted的代码更或者是相关文档,你都会感到非常的伤脑筋。 因此,我会用前面几个部分来介绍这个模型以让你掌握它的机制,稍后会介绍一下Twisted的特点。实际上,一开始,我们并不会使用Twisted,相反,会使用简单的Python来说明一个异步模型是如何工作的。我们在初次学习Twisted的时,会从你平常都不会直接使用的底层的实现讲起。Twisted是一个高度抽象的体系,因此在使用它时,你会体会到其多层次性。但当你去学习尤其是尝试着理解它是如何工作时

(转) Twisted :第二十二部分 结束

…衆ロ難τιáo~ 提交于 2019-11-30 16:41:43
全部完成 呼呼! 感谢你一路支持. 在我开始时完全没有想到这个系列会这样长,会花这么多时间完成,但是创建这个系列的过程使我非常享受,也希望你喜欢它. 既然我已经完成了,我会进一步考虑将其转化为PDF格式.然而,不保证. 最后,我想总结一些帮助你继续学习Twisted的建议. 进一步阅读 首先,我建议阅读Twisted的 在线文档 . 虽然它备受指责,但我觉得这总比饱受赞誉要好. 如果你希望使用Twisted进行网络编程, 那么 Jean-Paul Calderone 的广受关注的系列 Twisted网络编程60秒 是不错的选择. 虽然我觉得60秒可能读不完. 但比以上更重要的是,我认为,是阅读Twisted 源码 , 因为这些源码是被非常熟悉Twisted的人写的,其中的任何例子都会告诉你怎样用"Twisted的方式"做事情. 参考练习 将你写过的一个同步程序转化为使用Twisted. 从零开始,写一个Twisted程序. 从Twisted的 错误数据库 拾起一个错误,并修改它. 给Twisted的开发者提交一个补丁, 不要忘记阅读贡献源代码的 操作流程 . 真的要结束了 祝你编码快乐! 图47: 结束 来源: oschina 链接: https://my.oschina.net/u/2420772/blog/610328

User interaction in twisted process

眉间皱痕 提交于 2019-11-30 16:39:02
I am running a twisted process which needs to interact with the user, without blocking. The idea is that the user will be asked to input some data, and once a complete line has been entered, the program will process it, eventually triggering events. During the period that the user is entering data, the reactor must keep on running normally. Is there any support in twisted for that? You can read from standard input using twisted.internet.stdio . See stdiodemo.py and stdin.py at http://twistedmatrix.com/documents/current/core/examples/ . You can also use Gtk using twisted.internet.gtk2reactor .

Twisted errors in Scrapy spider

不问归期 提交于 2019-11-30 16:28:21
When I run the spider from the Scrapy tutorial I get these error messages: File "C:\Python26\lib\site-packages\twisted\internet\base.py", line 374, in fireEvent DeferredList(beforeResults).addCallback(self._continueFiring) File "C:\Python26\lib\site-packages\twisted\internet\defer.py", line 195, in addCallback callbackKeywords=kw) File "C:\Python26\lib\site-packages\twisted\internet\defer.py", line 186, in addCallbacks self._runCallbacks() File "C:\Python26\lib\site-packages\twisted\internet\defer.py", line 328, in_runCallbacks self.result = callback(self.result, *args, **kw) --- <exception

User interaction in twisted process

泪湿孤枕 提交于 2019-11-30 16:16:06
问题 I am running a twisted process which needs to interact with the user, without blocking. The idea is that the user will be asked to input some data, and once a complete line has been entered, the program will process it, eventually triggering events. During the period that the user is entering data, the reactor must keep on running normally. Is there any support in twisted for that? 回答1: You can read from standard input using twisted.internet.stdio. See stdiodemo.py and stdin.py at http:/

Twisted errors in Scrapy spider

試著忘記壹切 提交于 2019-11-30 16:08:14
问题 When I run the spider from the Scrapy tutorial I get these error messages: File "C:\Python26\lib\site-packages\twisted\internet\base.py", line 374, in fireEvent DeferredList(beforeResults).addCallback(self._continueFiring) File "C:\Python26\lib\site-packages\twisted\internet\defer.py", line 195, in addCallback callbackKeywords=kw) File "C:\Python26\lib\site-packages\twisted\internet\defer.py", line 186, in addCallbacks self._runCallbacks() File "C:\Python26\lib\site-packages\twisted\internet

ImportError with cx_Freeze and pyinstaller

自作多情 提交于 2019-11-30 15:20:12
I was using pyinstaller before to try and get my app with twisted as an executable, but I got this error when executing: Traceback (most recent call last): File "/usr/local/lib/python2.7/dist-packages/cx_Freeze/initscripts/Console.py", line 27, in <module> exec code in m.__dict__ File "client_test.py", line 2, in <module> File "/usr/local/lib/python2.7/dist-packages/Twisted-13.0.0-py2.7-linux-x86_64.egg/twisted/__init__.py", line 53, in <module> _checkRequirements() File "/usr/local/lib/python2.7/dist-packages/Twisted-13.0.0-py2.7-linux-x86_64.egg/twisted/__init__.py", line 37, in