June 16th, 2004, 04:11 PM
Problems Pickling after making a program a Daemon
Well i was writing a program which i needed to be a daemon. Iwas pickling objects inot and out of a file in that program. After I have made that program a daemon by the two fork method, the pickle doesnt seem to work. I write to a file (as it is a daemon,i dont "echo")before and after the pickle command,only the line before the pickle gets written. Have any of you had this probelm.It doesnt give any errors.
I have pasted the code also,and the file to read from.Please help me.
Here is the file 'newone' to read from.
flog = file("logfile","a")
fp = file('newone','r')
flog.write('hi In read Couldn\'t open %s for reading' %('newone'))
flog.write('new one opened in read mode\n')
templist = 
objlist = cPickle.load(fp)
flog.write('About to picle the items out')
pid = os.fork()
if pid > 0:
print >>sys.stderr, "fork #1 failed %d (%s)" % (e.errno,e.strerror)
#---make a clean process---
pid = os.fork()
if pid > 0:
except OSError, e:
print >>sys.stderr, "fork #2 failed %d (%s)" % (e.errno,e.strerror)
if __name__ == "__main__":
retcode = again_daemon()
Last edited by netytan; June 18th, 2004 at 04:43 AM.
Reason: Adding code tags get again.
June 17th, 2004, 04:18 AM
Please use a code tags and repost your question. Someone might be able to help.
Last edited by Grim Archon; June 17th, 2004 at 04:23 AM.
June 17th, 2004, 01:30 PM
hi had pasted the code with spacing corretcly.But dont know why it came without indentation.
June 17th, 2004, 05:32 PM
When you post code there are some code tags that make the code easier fore people to read. Look at the buttons right above the text field where you post and you'll find it.
June 18th, 2004, 02:18 AM
There is a Sticky message at the top of the forum that might be useful
June 18th, 2004, 02:56 AM
Click the "#" wrap (code) icon and paste your codes
June 18th, 2004, 04:45 AM
I've done this for you this time but in future could you please used them, this tread explains how to ask a question and the importance of using code tags with Python.
It also looks like you have an indentation error on the first line in read(). You seem to be using several different indentation levels all over the place i.e. some lines use 2 spaces and others 4 etc.
four spaces is the standard indentation level so i would probably use that.
Can i also sugest that you choose to use either file() or open() and not both for consistancy reasons . Also i would probably replace
print >> sys.stderr, 'error message'
which is equivelent to calling sys.exit('error message') but makes more sence to me at least. Just a few sugestions to get you stated .
raise SystemExit, 'error message'
Last edited by netytan; June 18th, 2004 at 05:27 AM.