Today I encountered a weird problem while running a python script with nohup. I was not getting anything in the output file even after waiting for 2-3 minutes which was unusual as I have used nohup on countless occasions with bash scripts and had not seen this issue.
Python itself buffers stdout and stderr which was causing this issue. So you have to explicitly disable buffering when you execute python scripts with nohup.
$nohup python -u script.py
With -u parameter python will disable the buffering and you will get all the outputs as it happens.
This is just an extension of the example shown here http://docs.python.org/library/xmlrpclib.html#example-of-client-usage .
import xmlrpclib, httplib
def set_proxy(self, proxy):
self.proxy = proxy
self.puser_pass = puser_pass
def make_connection(self, host):
self.realhost = host
h = httplib.HTTP(self.proxy)
def send_request(self, connection, handler, request_body):
connection.putrequest("POST", 'http://%s%s' % (self.realhost, handler))
def send_host(self, connection, host):
# Check is proxy username and password is set
if len(self.puser_pass.strip()) != 0:
p = ProxiedTransport()
proxyUsername = 'proxyuser'
proxyPassword = 'proxypass'
puser_pass = base64.encodestring('%s:%s' % (proxyUsername, proxyPassword)).strip()
server = xmlrpclib.Server('http://time.xmlrpc.com/RPC2', transport=p)
A similar code has been used in my blog client GScribble.