Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm trying to get upstart-socket-bridge to pass the socket to a Python3 application.

Are there any working examples of u-s-b using Python 2 or 3?

This example is a test setup only. u-s-b launches the Python3 application, but the file descriptor from Upstart seems invalid.

# Edited to remove lots of debug lines
import os, traceback, socket
fd = os.environ["UPSTART_FDS"]

# Log the socket connection activity
with open("/tmp/socket-test-outfile", 'w') as outfile:
    outfile.write("debug: fd={}\n".format(fd))
        s = socket.fromfd(fd, socket.AF_INET, socket.SOCK_STREAM)
        conn, addr = s.accept()
        outfile.write("s error: {}\n".format(traceback.print_exc()))

fd = 10 on all attempts so far. But that fd doesn't produce a useful socket that I can accept() and read(). The error output is None

>>> import socket
>>> s = socket.fromfd(10, socket.AF_INET, socket.SOCK_STREAM)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python3.3/", line 219, in fromfd
    nfd = dup(fd)
OSError: [Errno 9] Bad file descriptor

How can I get upstart-socket-bridge working with Python?

share|improve this question
Answer: There are a couple problems here. The specific error is the fd needs to be int(fd). Other fatal problems are addressed in a longer writeup:… – user535733 Dec 3 '13 at 13:22
Why not writing the content of the blog (not just the link) in the answer section below? – Braiam Dec 4 '13 at 0:17
Because it's really, really long. Bad assumptions, misunderstanding about how u-d-s works with sockets, etc. – user535733 Dec 5 '13 at 16:29
Ok, just copy the relevant parts and put it here. – Braiam Dec 5 '13 at 16:58
See the first comment. The shown error is resolved by a cast to int. I voted to close my own question here: Neither the question nor answer will help anybody else without a lot more context. Now that I understand more, I don't think it's a suitable or useful question/answer for the AskUbuntu format. – user535733 Dec 8 '13 at 13:19

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.