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))
try:
s = socket.fromfd(fd, socket.AF_INET, socket.SOCK_STREAM)
s.listen(1)
conn, addr = s.accept()
outfile.write("{}\n".format(conn.recv(1024).decode('UTF-8')))
except:
outfile.write("s error: {}\n".format(traceback.print_exc()))
outfile.close()
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/socket.py", line 219, in fromfd
nfd = dup(fd)
OSError: [Errno 9] Bad file descriptor
How can I get upstart-socket-bridge working with Python?
0 Answers