twisted

Running twistd as root, modules aren't found

别来无恙 提交于 2019-12-01 19:03:02
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 seems to be ignoring --rundir . even if I set that option explicitly. General UNIX wisdom is that

Twisted transport.write

牧云@^-^@ 提交于 2019-12-01 18:54:28
Is there any way to force self.transport.write(response) to write immediately to its connection so that the next call to self.transport.write(response) does not get buffered into the same call. We have a client with legacy software we cannot amend, that reads for the 1st request and then starts reading again, and the problem I have is twisted joins the two writes together which breaks the client any ideas i have tried looking into deferreds but i don't think it will help in this case Example: self.transport.write("|123|") # amount of messages to follow a loop to generate next message self

Twisted transport.write

余生颓废 提交于 2019-12-01 18:24:20
问题 Is there any way to force self.transport.write(response) to write immediately to its connection so that the next call to self.transport.write(response) does not get buffered into the same call. We have a client with legacy software we cannot amend, that reads for the 1st request and then starts reading again, and the problem I have is twisted joins the two writes together which breaks the client any ideas i have tried looking into deferreds but i don't think it will help in this case Example:

Using inlineCallbacks

拥有回忆 提交于 2019-12-01 15:16:17
问题 I'm new to Twisted and I'm trying to write a simple resource which displays a list of names from a database, here's a part of my code: #code from my ContactResource class def render_GET(self, request): def print_contacts(contacts, request): for c in contacts: request.write(c.name) if not request.finished: request.finish() d = Contact.find() #Contact is a Twistar DBObject subclass d.addCallback(print_contacts, request) return NOT_DONE_YET My question is: how can I change this method to use the

Python Twisted: restricting access by IP address

一世执手 提交于 2019-12-01 11:34:57
What would be the best method to restrict access to my XMLRPC server by IP address? I see the class CGIScript in web/twcgi.py has a render method that is accessing the request... but I am not sure how to gain access to this request in my server. I saw an example where someone patched twcgi.py to set environment variables and then in the server access the environment variables... but I figure there has to be a better solution. Thanks. When a connection is established, a factory's buildProtocol is called to create a new protocol instance to handle that connection. buildProtocol is passed the

Trial unittests using Autobahn WebSocket

爷,独闯天下 提交于 2019-12-01 09:15:11
I'm trying to write unittests for my application that uses Autobahn. I want to test my controllers which gets received data from protocol, parses it and reacts to it. But when my test comes to a point when protocol should be disconnected ( self.sendClose ) then it raises error exceptions.AttributeError: 'MyProtocol' object has no attribute 'state'. I was trying to makeConnection using proto_helpers.StringTransport but then I have errors too exceptions.AttributeError: StringTransport instance has no attribute 'setTcpNoDelay'` I'm using trial and I don't want to run dummy server/client for

Python Twisted: restricting access by IP address

非 Y 不嫁゛ 提交于 2019-12-01 09:11:10
问题 What would be the best method to restrict access to my XMLRPC server by IP address? I see the class CGIScript in web/twcgi.py has a render method that is accessing the request... but I am not sure how to gain access to this request in my server. I saw an example where someone patched twcgi.py to set environment variables and then in the server access the environment variables... but I figure there has to be a better solution. Thanks. 回答1: When a connection is established, a factory's

How do I get my simple twisted proxy to work?

时间秒杀一切 提交于 2019-12-01 09:03:42
I am attempting to make use of the Twisted.Web framework. Notice the three line comments (#line1, #line2, #line3). I want to create a proxy (gateway?) that will forward a request to one of two servers depending on the url. If I uncomment either comment 1 or 2 (and comment the rest), the request is proxied to the correct server. However, of course, it does not pick the server based on the URL. from twisted.internet import reactor from twisted.web import proxy, server from twisted.web.resource import Resource class Simple(Resource): isLeaf = True allowedMethods = ("GET","POST") def getChild(self

Proper way to close all files after subprocess Popen and communicate

纵饮孤独 提交于 2019-12-01 08:29:57
We are having some problems with the dreaded "too many open files" on our Ubuntu Linux machine rrunning a python Twisted application. In many places in our program, we are using subprocess Popen, something like this: Popen('ifconfig ' + iface, shell=True, stdin=PIPE, stdout=PIPE, stderr=STDOUT, close_fds=True) output = process.stdout.read() while in other places we use subprocess communicate: process = subprocess.Popen(['/usr/bin/env', 'python', self._get_script_path(script_name)], stdin=subprocess.PIPE, stdout=subprocess.PIPE, close_fds=True) out, err = process.communicate(data) What exactly

twisted - interrupt callback via KeyboardInterrupt

 ̄綄美尐妖づ 提交于 2019-12-01 08:18:47
I'm currently repeating a task in a for loop inside a callback using Twisted, but would like the reactor to break the loop in the callback (one) if the user issues a KeyboardInterrupt via Ctrl-C. From what I have tested, the reactor only stops or processes interrupts at the end of the callback. Is there any way of sending a KeyboardInterrupt to the callback or the error handler in the middle of the callback run? Cheers, Chris #!/usr/bin/env python from twisted.internet import reactor, defer def one(result): print "Start one()" for i in xrange(10000): print i print "End one()" reactor.stop()