Posts tagged with python

Find a random unbound port

Filed in: Python

find_unbound_port returns a (pseudo-)random unbound port on localhost. import random import socket # range of ports where available ports can be found PORT_RANGE = [33000,60000] def find_unbound_port(): “”" Returns an unbound port number on 127.0.0.1. “”" port = random.randint(*PORT_RANGE) sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) try: sock.bind((“127.0.0.1″, port)) except socket.error: port = get_port() return port if __name__ [...]

Read more...

Per Instance Settings in gondor.io

Filed in: Django

It’s easy to have different Django settings per instance in gondor.io. For each instance create a deploy/settings_<instance_name>.py module and specify your settings there. A simple use case for this is to have DEBUG on for a development instance but off for production. In this case set DEBUG=False in the project’s settings.py module, and set DEBUG=True [...]

Read more...

Getting EC2 regions using Boto

Filed in: Python

The following snippet in the Boto documentation is used to get a list of EC2 regions: import boto.ec2 regions = boto.ec2.regions() Unfortunately when executed this code raises the following error: Traceback (most recent call last): … regions = boto.ec2.regions() File “…/site-packages/boto/ec2/__init__.py”, line 38, in regions c = EC2Connection(**kw_params) File “…/site-packages/boto/ec2/connection.py”, line 80, in __init__ https_connection_factory, [...]

Read more...

libjpeg 8c not compatible with PIL 1.1.7

Filed in: Python

I used Homebrew to install libjpeg and PIL and got the following error: $ python -c “import _imaging” Traceback (most recent call last): File “”, line 1, in ImportError: dlopen(/usr/local/Cellar/python/2.7.1/ \ lib/python2.7/site-packages/PIL/_imaging.so, 2): Library not loaded: \ /usr/local/Cellar/jpeg/8c/lib/libjpeg.8.dylib Referenced from: /usr/local/Cellar/python/2.7.1/ \ lib/python2.7/site-packages/PIL/_imaging.so Reason: Incompatible library version: _imaging.so requires \ version 12.0.0 or later, but [...]

Read more...

Python bug weekend

Filed in: Python

This coming weekend Python-dev are organising a bug weekend. We would like to encourage anyone who feels interested in participating to give it a try. Contributing to Python is much less intimidating than it sounds. You don’t need to have previous experience with modifying the Python source; in fact bug days offer a good opportunity [...]

Read more...