twisted

How to test LoopingCall()?

为君一笑 提交于 2019-12-04 12:06:53
Within my code, I use task.LoopingCall() to run some deferred function every second. I want to make sure that that function returns the right values for a certain number of things. So, I thought I could use a task.clock() and call the advance() method on it. However, I am not getting the right number of responses expected. Any idea what I am doing wrong? Here is a test code to show what I mean. First is the server: from twisted.internet.protocol import Factory from twisted.protocols.basic import LineReceiver from twisted.internet import reactor from twisted.internet import task import time

Connecting twice with twisted - how to do that correctly?

邮差的信 提交于 2019-12-04 12:01:44
问题 I want to use twisted (and StarPy which is a protocol implementation for asterisk ami) to connect to an asterisk server. The application initiates a outgoing fax there. I found some hints on my problem, but I cannot find out how to handle this correctly. The first fax is sent out correctly. Problem is, if I call twisted for the second time, the application keeps hanging in main loop. I know I may NOT do this like here: from starpy import manager from twisted.internet import reactor def main()

Why I am Getting '_SIGCHLDWaker' object has no attribute 'doWrite' in Scrapy?

ε祈祈猫儿з 提交于 2019-12-04 10:01:38
问题 I am using Scrapy spiders inside Celery and I am getting this kind of errors randomly Unhandled Error Traceback (most recent call last): File "/usr/lib/python2.7/site-packages/twisted/python/log.py", line 103, in callWithLogger return callWithContext({"system": lp}, func, *args, **kw) File "/usr/lib/python2.7/site-packages/twisted/python/log.py", line 86, in callWithContext return context.call({ILogContext: newCtx}, func, *args, **kw) File "/usr/lib/python2.7/site-packages/twisted/python

twisted not detecting client disconnects

狂风中的少年 提交于 2019-12-04 09:39:19
Does anybody have experience with this? I have a twisted app. The clients connect to the server. I added a feature so that if a client connects to a server, but there's already a client from that IP address running, it disconnects the new client. Once in a while, I shutdown a client computer (or VM, to be precise) without manually turning off the Python program. When I do this, once in a while but pretty often, the server does not detect any disconnect. When the computer comes back up and tries to reconnect, the server insists that there is a connection from that IP already. The only solution

Tail -f log on server, process data, then serve to client via twisted

随声附和 提交于 2019-12-04 08:36:49
问题 Goal: Show data from server in wxPython GUI on client Newcomer to Twisted. I have a wxPython GUI running on a Windows 7 client, and I have a program running on an Ubuntu server that produces a log. My current attempt is to tail -f the log, pipe the output to a twisted server, then serve any data that meets my regex conditions to the client. I already have a tunnel open, so I don't need to complicate things with SSH. I've gotten the following block of code running, but it only serves the first

Stopping Twisted from swallowing exceptions

喜夏-厌秋 提交于 2019-12-04 08:03:23
问题 Is there a way to stop Twisted reactor from automatically swallowing exceptions (eg. NameError)? I just want it to stop execution, and give me a stack trace in console? There's even a FAQ question about it, but to say the least, it's not very helpful. Currently, in every errback I do this: def errback(value): import traceback trace = traceback.format_exc() # rest of the errback... but that feels clunky, and there has to be a better way? Update In response to Jean-Paul's answer, I've tried

Unable to install twisted package on windows machine

谁说我不能喝 提交于 2019-12-04 05:47:34
I have got python2.6 installed on my windows machine. tried to install twisted package but unable to install it. Also installed the zope interface On the python interpretor I get the error as : >>>import twisted >>>Import Error: No Module named twisted I installed the package twisted succesfully. C:\Documents and Settings\tazim_kolhar>python Python 2.6 (r26:66721, Oct 2 2008, 11:35:03) [MSC v.1500 32 bit (Intel)] on win 32 Type "help", "copyright", "credits" or "license" for more information. >>> import twisted >>> ^Z But when, I try to run the script containing the package : C:\Documents and

How debuging twisted application in PyCharm

与世无争的帅哥 提交于 2019-12-04 05:30:32
问题 I would like to debug a Twisted Application in PyCharm from twisted.internet import defer from twisted.application import service, internet from txjason.netstring import JSONRPCServerFactory from txjason import handler class Example(handler.Handler): def __init__(self, who): self.who = who @handler.exportRPC("add") @defer.inlineCallbacks def _add(self, x, y): yield defer.returnValue(x+y) @handler.exportRPC() def whoami(self): return self.who factory = JSONRPCServerFactory() factory.addHandler

Store an instance of a connection - twisted.web

自作多情 提交于 2019-12-04 05:27:53
问题 How I store an instance of a connection in twisted.web? I have seen request.getSession() but I searched and there are very few examples of how it is stored and retrieved later. Thanks. Update: I want to store the ldap connection in a session for retrieve later def render_POST(self, request): command = request.path[1:] session = request.getSession() if command == "authentication": Connect = LdapConnection(request.args['host'][0],request.args['user'][0],request.args['password'][0]) session

Determine the current number of backlogged connections in TCP listen() queue

北城以北 提交于 2019-12-04 04:48:19
Is there a way to find out the current number of connection attempts awaiting accept() on a TCP socket on Linux? I suppose I could count the number of accepts() that succeed before hitting EWOULDBLOCK on each event loop, but I'm using a high-level library (Python/Twisted) that hides these details. Also it's using epoll() rather than an old-fashioned select()/poll() loop. I am trying to get a general sense of the load on a high-performance non-blocking network server, and I think this number would be a good characterization. Load average/CPU statistics aren't helping much, because I'm doing a