Jump to content

python fixing


XSV_SOLJA

Recommended Posts

  • 2 weeks later...

okay okay you want the source code

 

 

 

beginging:

it gives an error with 'pid = os.fork()' and says module doesnt have 'fork' :blink:

import sys
from socket import *
import string
import os
import time
import popen2
import signal

def daemonize():
pid = os.fork()
if(pid != 0):
	os._exit(0)

 

...and a whole lot of code...

 

 

 

ending:

im guessing that once above error is fixed this will come as well. it just says that 'daemonize()' has an error, and no discription :confused:blink:

if __name__ == "__main__":
daemonize()
main()

 

Edited by XSV_SOLJA
Link to comment
Share on other sites

I would need a little bit more information...

What OS are you trying to run this script on?

What python version are you using?

 

If I had to debug the code, I would try to use a script already done with the fork() function to know if you have it on your system. So try this code:

 


#!/usr/bin/env python

import os, sys

print "I'm going to fork now - the child will write something to a pipe, and the parent will read it back"

r, w = os.pipe() # these are file descriptors, not file objects

pid = os.fork()
if pid:
   # we are the parent
   os.close(w) # use os.close() to close a file descriptor
   r = os.fdopen(r) # turn r into a file object
   print "parent: reading"
   txt = r.read()
   os.waitpid(pid, 0) # make sure the child process gets cleaned up
else:
   # we are the child
   os.close(r)
   w = os.fdopen(w, 'w')
   print "child: writing"
   w.write("here's some text from the child")
   w.close()
   print "child: closing"
   sys.exit(0)

print "parent: got it; text =", txt

 

Copy/paste from http://www.myelin.co...post/2003/3/13/

 

It works perfectly on my Suse box:

[17:08:13 root@jodion.rp10:~ ()]# ./test.py
I'm going to fork now - the child will write something to a pipe, and the parent will read it back
parent: reading
child: writing
child: closing
parent: got it; text = here's some text from the child

 

 

From the Python docs:

os.fork()

Fork a child process. Return 0 in the child and the child’s process id in the parent. If an error occurs OSError is raised.

Note that some platforms including FreeBSD <= 6.3, Cygwin and OS/2 EMX have known issues when using fork() from a thread.

Availability: Unix.

 

 

So if you are using Windows + cygwin, it might not work perfectly...

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.