I've been running into problem file descriptor run out using the default reactor. By default, twisted got hardcode the file descriptor to be 1024 (MAX). If you want to change the default MAX need to modify code and recompile. Or we can use the pollreactor to increase several thousand more.
>>
from twisted.internet import pollreactor
pollreactor.install()
<<
usage as normal:
from twisted.internet import reactor
Even if you change the ulimit on filesystem, it doesn't change with the library. This is something hardcode inside twisted lib.
Tuesday, March 23, 2010
Creating a self-signed cert with one command
Creating a self-signed cert with one command
The following command will generate a new key and create a certificate all in one line suitable for use by Apache or any other SSL tool.
openssl req -new -newkey rsa:1024 -days 365 -nodes -x509 -keyout www.example.com.pem -out www.example.com.pem
You can then use the file above in apache with the following two lines
SSLEngine On
SSLCertificateFile www.example.com.pem
The following command will generate a new key and create a certificate all in one line suitable for use by Apache or any other SSL tool.
openssl req -new -newkey rsa:1024 -days 365 -nodes -x509 -keyout www.example.com.pem -out www.example.com.pem
You can then use the file above in apache with the following two lines
SSLEngine On
SSLCertificateFile www.example.com.pem
Monday, March 22, 2010
python twisted interrupt signal handler
from twisted.internet import reactor
import signal
def shutdown(*f):
sig, ob = f
if sig == signal.SIGINT: reactor.stop() #shutdown the reactor if Ctrl-C enter.
signal.signal(signal.SIGINT, shutdown)
reator.run(installSignalHandlers=0)
twisted.web2 auto reconnecting browser
Making use web2 Broker Class from http://code.google.com/p/twisted-web2-client
class Browser:
#Init Channel
#Authenticate Channel
#Send Channel
#Recieve Channel
def __init__(self, timeout=180 ):
self.timeout = timeout
self.conn = Broker()
self.headers = {}
self.response_headers = None
def parse_response_headers(self, headers):
self.response_headers = headers
self.raw_headers = headers._raw_headers
if headers.hasHeader('set-cookie'):
parseSetCookies = http_headers.parseSetCookie(headers.getRawHeaders('set-cookie'))
self.headers['Cookie']= parseSetCookies
def getResponseBody(self, resp):
d = defer.Deferred()
self.parse_response_headers(resp.headers)
stack = []
stream_mod.readStream(resp.stream, stack.append).addCallback(lambda x: ''.join(stack)).addCallbacks(d.callback, d.errback)
return d
def connect(self, uri, postdata=None, method='GET', *args, **kwargs):
d = self.conn.ask(uri, method, self.headers, postdata,timeout=self.timeout, *args, **kwargs).addCallback(self.getResponseBody)
return d
Monday, March 8, 2010
httpclient for twisted web2
Here is excellent tutorial for twisted web2 client.
http://code.google.com/p/twisted-web2-client/
Thanks to the author, I've spend quite sometime to google, but no luck!
http://code.google.com/p/twisted-web2-client/
Thanks to the author, I've spend quite sometime to google, but no luck!
Friday, March 5, 2010
install and config weblizer on ubuntu
http://fontignie.blogspot.com/2006/04/install-and-configure-webalizer-on.html
Install and configure webalizer on Ubuntu
- install webalizer
If webalizer is not found, you have to add sources in /etc/apt/sources.list: can comment the universe sources.sudo apt-get install webalizer
- Enable the apache2 hostname resolution: go into /etc/apache2/apache2.conf: Change
intoHostnameLookups Off
HostnameLookups On
- By default webalizer is not well configured: it does not check in the good log. In /etc/webalizer.conf: Change
to
LogFile /var/log/apache2/access.log.1LogFile /var/log/apache2/access.log
- Test webalizer:
sudo webalizer
If you get a warning like warning: Truncating ...
It is because you did not put the hostnameLookup. If afterward, you get this message, it can be because you are attacked by a virus... - Run webalizer as a cronjob. This has to be run as root: Edit the root cronjobs by running the command:
and add the line:sudo crontab -e
With that line, every hour webalizer is run0 * * * * webalizer
install and config weblizer on ubuntu
http://fontignie.blogspot.com/2006/04/install-and-configure-webalizer-on.html
Install and configure webalizer on Ubuntu
- install webalizer
If webalizer is not found, you have to add sources in /etc/apt/sources.list: can comment the universe sources.sudo apt-get install webalizer
- Enable the apache2 hostname resolution: go into /etc/apache2/apache2.conf: Change
intoHostnameLookups Off
HostnameLookups On
- By default webalizer is not well configured: it does not check in the good log. In /etc/webalizer.conf: Change
to
LogFile /var/log/apache2/access.log.1LogFile /var/log/apache2/access.log
- Test webalizer:
sudo webalizer
If you get a warning like warning: Truncating ...
It is because you did not put the hostnameLookup. If afterward, you get this message, it can be because you are attacked by a virus... - Run webalizer as a cronjob. This has to be run as root: Edit the root cronjobs by running the command:
and add the line:sudo crontab -e
With that line, every hour webalizer is run0 * * * * webalizer
Subscribe to:
Posts (Atom)