twisted

Mutex in Python Twisted

I'm using the Twisted framework, and am getting RPCs asynchronously. I have another function which does a task every 2 seconds, and sleeps in between. This is called through reactor.callInThread. These depend on a shared resources, so I need some thread-safe way of accessing them. How does one go about using critical sections / mutexes /...

How to add hooks in twisted.web (or twisted.web2)?

How can I add a hook before and after processing a request on twisted.web (twisted.web2 is fine too)? The equivalent of webpy's: app = web.application(urls, globals()) app.add_processor(web.loadhook(my_attach_callback)) app.add_processor(web.unloadhook(my_detach_callback)) Thanks! ...

CherryPy interferes with Twisted shutting down on Windows

I've got an application that runs Twisted by starting the reactor with reactor.run() in my main thread after starting some other threads, including the CherryPy web server. Here's a program that shuts down cleanly when Ctrl+C is pressed on Linux but not on Windows: from threading import Thread from signal import signal, SIGINT import ...

Twisted sometimes throws (seemingly incomplete) 'maximum recursion depth exceeded' RuntimeError

Because the Twisted getPage function doesn't give me access to headers, I had to write my own getPageWithHeaders function. def getPageWithHeaders(contextFactory=None, *args, **kwargs): try: return _makeGetterFactory(url, HTTPClientFactory, contextFactory=contextFactory, ...

python program choice

My program is ICAPServer (similar with httpserver), it's main job is to receive data from clients and save the data to DB. There are two main steps and two threads: ICAPServer receives data from clients, puts the data in a queue (50kb <1ms); another thread pops data from the queue, and writes them to DB SO, if 2nd step is too slow, th...

Error running twisted application

I am trying to run a simple twisted application echo bot that metajack blogged about, everything looks like it is going to load fine, but at the very end I get an error: 2009/07/12 15:46 -0600 [-] ImportError: cannot import name toResponse 2009/07/12 15:46 -0600 [-] Failed to load application: cannot import name toResponse Any ideas o...

How to update the twisted framework

I can see from the latest 8.2 (almost 1200 lines of code) twisted that I am missing something: http://twistedmatrix.com/trac/browser/trunk/twisted/words/protocols/jabber/xmlstream.py My copy (697 lines from 3 years ago) is in: /System/Library/Frameworks/Python.framework/Versions/2.5/Extras/lib/python/twisted/words/protocols/jabber/xmlst...

win32api.dll Will Not Install

I am trying to start a Buildbot Buildslave on a Windows XP virtual machine: python buildbot start . ImportError: No module named win32api. Google tells me that win32api is win32api.dll. I downloaded the file from www.dll-files.com and followed the guide found on that site (http://www.dll-files.com/unzip.php). When I try to run regv...

fast-ish python/jython IPC?

All I want to do is make some RPC calls over sockets. I have a server that does backendish stuff running jython 2.5. I need to make some calls from a frontend server running Django on CPython. I've been beating my head against a wall getting any form of IPC going. The list of things I've tried: Apache Thrift doesn't have any actual re...

How to increase connection pool size for Twisted?

Hello I'm using Twisted 8.1.0 as socket server engine. Reactor - epoll. Database server is MySQL 5.0.67. OS - Ubuntu Linux 8.10 32-bit in /etc/mysql/my.cnf: max_connections = 1000 in source code: adbapi.ConnectionPool("MySQLdb", ..., use_unicode = True, charset='utf8', cp_min=3, cp_max=700, cp_noisy=False) But i...

Templating+scripting reverse proxy?

Thinking through an idea, wanted to get feedback/suggestions: Having had great success with url rewriting and nginx, I'm now thinking of a more capable reverse proxy/router that would do the following: Map requests to handlers based on regex matching (ala Django) Certain requests would simply be routed to backend servers - eg. static ...

Problem with Twisted python - sending binary data

What I'm trying to do is fairly simple: send a file from client to server. First, the client sends information about the file - the size of it that is. Then it sends the actual file. This is what I've done so far: Server.py from twisted.internet import reactor, protocol from twisted.protocols.basic import LineReceiver import pickle i...

In Twisted Python - Make sure a protocol instance would be completely deallocated

Hey, I have a pretty intensive chat socket server written in Twisted Python, I start it using internet.TCPServer with a factory and that factory references to a protocol object that handles all communications with the client. How should I make sure a protocol instance completely destroys itself once a client has disconnected? I've got...

Help me understand this traceback from the twisted.words msn sample

I'm running the twisted.words msn protocol example from the twisted documentation located here: http://twistedmatrix.com/projects/words/documentation/examples/msn_example.py I am aware there is another question about this sample .py on stackoverflow, but this is an entirely different problem. When I run the example, it behaves as expect...

Network Support for Pygame

I am making a simple multiplayer economic game in pygame. It consists of turns of a certain length, at the end of which, data is sent to the central server. A few quick calculations are done on the data and the results are sent back to the players. My question is how I should implement the network support. I was looking at Twisted and at...

Python Twisted: restricting access by IP address

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 th...

Cannot connect to server externally using Twisted library in Python

I am trying to get a simple TCP server running on my server. I am using echoserv.py and echoclient.py on the Twisted examples page. When I run echoserv.py on the server, I can connect fine using the following in echoclient.py: reactor.connectTCP('localhost', 8000, factory) <- for a localhost connection reactor.connectTCP('192.168.0.250'...

Using Heapy's Memory Profile Browser with Twisted.web

I am trying to profile twisted python code with Heapy. For example (pseudo code): from twisted.web import resource, server from twisted.internet import reactor from guppy import hpy class RootResource(resource.Resource): render_GET(self, path, request): return "Hello World" if __name__ == '__main__': h = hpy() por...

How do I switch this Proxy to use Proxy-Authentication?

I'm trying to modify my simple Twisted web proxy to use "Proxy-Authentication" (username/password) instead of the current IP based authentication. Problem is, I'm new to Twisted and don't even know where to start. Here is my Factory Class. class ProxyFactory(http.HTTPFactory): def __init__(self, ip, internal_ips): http.H...

Managing multiple Twisted client connections

I'm trying to use Twisted in a sort of spidering program that manages multiple client connections. I'd like to maintain of a pool of about 5 clients working at one time. The functionality of each client is to connect to a specified IRC server that it gets from a list, enter a specific channel, and then save the list of the users in tha...