Os.setsid operation not allowed

Ok what's wrong with me there seems to be some answers on google about this but I just can't get it.

I run it after two forks in the Django Celery environment. I don't know if they could have changed something, but I guess they didn't.

There is not much code to leave it as powerful

if __name__ == '__main__':
    os.setsid()

      

provides me with a wonderful operation, not authorized

I am running the latest stable versions of Django, Debian, Celery and Python.

+3


source to share


1 answer


Python os.setsid()

is possibly calling the underlying library setsid(3)

.

Complete ERRORS section in man 3 setsid

:

ERRORS
   EPERM  The  process group ID of any process equals the PID of the call-
          ing process.  Thus, in particular, setsid() fails if the calling
          process is already a process group leader.

      

IOW: The only reason for failure setsid()

is when the calling process is already the leader of the process group. Ergo: you can ignore the failure. To verify that this is the case, compare what you return with getpid()

and getpgid()

when it os.setsid()

fails:

#!/usr/bin/env python

import os
import errno

if __name__ == '__main__':
    try:
        os.setsid()
    except OSError, (err_no, err_message):
        print "os.setsid failed: errno=%d: %s" % (err_no, err_message)
        print "pid=%d  pgid=%d" % (os.getpid(), os.getpgid(0))

      



When I run the above, I get:

os.setsid failed: errno=1: Operation not permitted
pid=17025  pgid=17025

      

Note that the process id (pid) is equal to the process-group-id (pgid), which means that this process is indeed the leader of the process group.

PS: Yes, it's a daunting python feature to raise exceptions where a simple error return code is enough to distinguish success from failure (just like normal Un * x APIs libc

). This is unfortunately how the python call interface interface is implemented, so you need to wrap a lot of system calls with constructs try: except ...:

to prevent the python code from interrupting.

+3


source







All Articles