Python Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesPython Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old June 16th, 2004, 04:11 PM
haoscar haoscar is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2004
Posts: 2 haoscar User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Problems Pickling after making a program a Daemon

hi all,
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.

***************************
Code:
import os
import sys

def read(objlist):
   flog = file("logfile","a")
    try:
        fp = file('newone','r')
    except IOError:
        flog.write('hi In read Couldn\'t open %s for reading' %('newone'))
        sys.exit()
    else:
        flog.write('new one opened in read mode\n')
    i=0
    flag=0
    templist = []
    objlist = cPickle.load(fp)
    flog.write('About to picle the items out')
    flog.write(str(len(objlist)))
    flog.close()

def again_daemon():
    try:
        pid = os.fork()
        if pid > 0:
            #---first parent
            sys.exit(0)
    except OSError,e:
        print >>sys.stderr, "fork #1 failed %d (%s)" % (e.errno,e.strerror)
        sys.exit(1)
    #---make a clean process---
    os.chdir('/')
    os.setsid()
    os.umask(000)
    child_in =open('/dev/null','r')
    child_out=open('/dev/null','w')
    os.dup2(child_in.fileno(), sys.stdin.fileno())
    os.dup2(child_out.fileno(), sys.stdout.fileno())
    os.dup2(child_out.fileno(), sys.stderr.fileno())
    #---second fork---
    try:
        pid = os.fork()
        if pid > 0:
            #---second parent---
            sys.exit(0)
    except OSError, e:
        print >>sys.stderr, "fork #2 failed %d (%s)" % (e.errno,e.strerror)
        sys.exit(1)
    return (0)

if __name__ == "__main__":
 objlist =[]
 retcode = again_daemon()
 read(objlist) 

Here is the file 'newone' to read from.
(lp1
(i__main__
entry
p2
(dp3
S'remark'
p4
S'none'
sS'title'
p5
S'Meet Devshed.'
sS'day'
p6
I16
sS'time'
p7
S'9 am'

Last edited by netytan : June 18th, 2004 at 04:43 AM. Reason: Adding code tags get again.

Reply With Quote
  #2  
Old June 17th, 2004, 04:18 AM
Grim Archon's Avatar
Grim Archon Grim Archon is offline
Mini me.
Dev Shed Novice (500 - 999 posts)
 
Join Date: Nov 2003
Location: Cambridge, UK
Posts: 783 Grim Archon User rank is Corporal (100 - 500 Reputation Level)Grim Archon User rank is Corporal (100 - 500 Reputation Level)Grim Archon User rank is Corporal (100 - 500 Reputation Level)Grim Archon User rank is Corporal (100 - 500 Reputation Level)  Folding Points: 1488 Folding Title: Novice Folder
Time spent in forums: 3 Days 2 h 15 m 57 sec
Reputation Power: 7
Send a message via MSN to Grim Archon
Please use a code tags and repost your question. Someone might be able to help.
__________________
*** Experimental Python Markup CGI V2 ***

Last edited by Grim Archon : June 17th, 2004 at 04:23 AM.

Reply With Quote
  #3  
Old June 17th, 2004, 01:30 PM
haoscar haoscar is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2004
Posts: 2 haoscar User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
hi had pasted the code with spacing corretcly.But dont know why it came without indentation.

Reply With Quote
  #4  
Old June 17th, 2004, 05:32 PM
Theeggman Theeggman is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2001
Posts: 266 Theeggman User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 30 m 33 sec
Reputation Power: 8
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.

Reply With Quote
  #5  
Old June 18th, 2004, 02:18 AM
Grim Archon's Avatar
Grim Archon Grim Archon is offline
Mini me.
Dev Shed Novice (500 - 999 posts)
 
Join Date: Nov 2003
Location: Cambridge, UK
Posts: 783 Grim Archon User rank is Corporal (100 - 500 Reputation Level)Grim Archon User rank is Corporal (100 - 500 Reputation Level)Grim Archon User rank is Corporal (100 - 500 Reputation Level)Grim Archon User rank is Corporal (100 - 500 Reputation Level)  Folding Points: 1488 Folding Title: Novice Folder
Time spent in forums: 3 Days 2 h 15 m 57 sec
Reputation Power: 7
Send a message via MSN to Grim Archon
There is a Sticky message at the top of the forum that might be useful

Reply With Quote
  #6  
Old June 18th, 2004, 02:56 AM
pyton pyton is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2004
Posts: 45 pyton User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 5
Click the "#" wrap (code) icon and paste your codes

Reply With Quote
  #7  
Old June 18th, 2004, 04:45 AM
netytan's Avatar
netytan netytan is offline
Hello World :)
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Mar 2003
Location: Hull, UK
Posts: 2,536 netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 1 Week 2 Days 18 h 3 m 4 sec
Reputation Power: 63
Send a message via ICQ to netytan Send a message via AIM to netytan Send a message via MSN to netytan Send a message via Yahoo to netytan
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

Code:
print >> sys.stderr, 'error message'
sys.exit(1)


with

Code:
raise SystemExit, '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 .

Later,

Mark.
__________________
programming language development: www.netytan.com Hula


Last edited by netytan : June 18th, 2004 at 05:27 AM.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPython Programming > Problems Pickling after making a program a Daemon


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway
Stay green...Green IT