Launch a process using subprocess
I would like to launch a process (audacity) using subprocess and that process should not close until I close it Can any please tell me how to do it using subprocess in Python?
See also questions close to this topic
How to detach Python child process on Windows (without setsid)?
I'm migrating some process code to Windows which worked well on Posix. Very simply put: the code to launch a subprocess and immediately detach will not work because
setsid()is not available:
import os, subprocess, sys p = subprocess.Popen([sys.executable, '-c', "print 'hello'"], preexec_fn=os.setsid)
I can remove the use of
setsidbut then the child process ends when the parent ends.
My question is how do I achieve the same effect as
setsidon Windows so that the child process lifetime is independent of the parent's?
I'd be willing to use a particular Python package if one exists for this sort of thing. I'm already using
psutilfor example but I didn't see anything in it that could help me.
What Does def __init__(self, master) Mean?
Today I have begun looking into using Python to create a Graphical User Interface (GUI), more for fun than for productivity. I bounced from article to article, and it has led me to tkinter, which seems to have the most documentation and seems to be the most human-readable, so that is what I chose to follow. I found a tutorial for it online, and I typed it in myself; that led to an error, so I just copied and pasted it into the instance of Jupyter Notebook I'm using to make sure that it works at all, and it does, this is the code:
from tkinter import Tk, Label, Button class MyFirstGUI: def __init__(self, master): self.master = master master.title("A simple GUI") self.label = Label(master, text="This is our first GUI!") self.label.pack() self.greet_button = Button(master, text="Greet", command=self.greet) self.greet_button.pack() self.close_button = Button(master, text="Close", command=master.quit) self.close_button.pack() def greet(self): print("Greetings!") root = Tk() my_gui = MyFirstGUI(root) root.mainloop()
So my question doesn't pertain to a problem I'm having with code, I'm just wondering what the line
def __init__(self, master):
means and what the "self"'s littered throughout this script works.
Thanks so much for any answers. Have a great afternoon!
Base Abstract Class: ConsultantModel.py
class ConsultantModel(DeclarativeBase): __tablename__ = 'consultant' __abstract__ = True
Sub class 1: Consultant.py
Sub class 2: Staff.py
TG Controller: SetupController.py
from phb.model import DBSession class SetupController(BaseController): def _before(self, *args, **kw): self.user_id = request.identity['user'].user_id self.consultant = DBSession.query(Consultant).filter_by(user_id=self.user_id).one() def staff(self): staff = Staff() staff.name = 'john' DBSession.add(staff) self.__updateStep() def __updateStep(self): self.consultant.completed = self.current_step + 1 DBSession.add(self.consultant)
The problematic code is
self.consultant.completed = self.current_step + 1No errors occur if I remove this line.