Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AttributeError: module 'os' has no attribute 'setsid'

Tags:

python

I am trying to connect to MongoDB using Anaconda3 (64-bit). The code I am using:

import signal
import subprocess



proc = subprocess.Popen(['mongod'] preexec_fn=os.setsid)

But I am getting below error

AttributeError                            
Traceback (most recent call last) <ipython-input-45-f94c14f3a553> in <module>()
      2 import subprocess
      3 #proc = subprocess.Popen('mongod', close_fds=True)
----> 4 proc =subprocess.Popen(['mongod'], shell=True, preexec_fn=os.setsid)

AttributeError: module 'os' has no attribute 'setsid'
like image 456
Ameer B. Avatar asked Jun 28 '16 17:06

Ameer B.


1 Answers

On Windows, you cannot use os.setsid, preexec_fn parameter subprocess.Popen also unavailable.

You can create a subprocess with a new process group with creationflags` parameter documentation:

proc = subprocess.Popen(
    ['mongod'],
    shell=True,
    creationflags=subprocess.CREATE_NEW_PROCESS_GROUP
)
like image 56
Виктор Дремов Avatar answered Oct 18 '22 19:10

Виктор Дремов