Python Forum

Full Version: Where is Popen.pid?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Described in https://docs.python.org/3/library/subprocess.html.

But I run python3 on my program
def Output_text (MyString, Xoffset, Yoffset, fg_color, bg_color, Font_size):
    global screen_width
    global screen_height
    global Python3
    global Kill_pos, Killz

    print (Kill_pos, Killz)
    killval=Killz[Kill_pos]
    if Kill_pos == 0:
        p1=Popen ([Python3, 'Programs/Message.py', str(Xoffset), str(Yoffset), Font_size, fg_color, bg_color,MyString])
        return()
    else:
        if killval > 0: os.kill(killval, signal.SIGUSR1)
        p1=Popen ([Python3, 'Programs/Message.py', str(Xoffset), str(Yoffset), Font_size, fg_color, bg_color,MyString])
        Killz[Kill_pos]=Popen.pid
        print (Kill_pos, Killz, Popen.pid)
    return
and get
Quote:Traceback (most recent call last):
File "test_morse_practice.py", line 194, in <module>
Output_text (input_msg, XStart, YStart, Data_Font_fg_color, Data_Font_bg_color, Prompt_Font_Size)
File "test_morse_practice.py", line 108, in Output_text
Killz[Kill_pos]=Popen.pid
AttributeError: type object 'Popen' has no attribute 'pid'

Thee Popen works. It's the Popen.pid it doesn't like.

My imports are:
import random
import signal
import os
from subprocess import Popen
You probably want p1.pid; how is Python supposed to know you want p1 when you only reference Popen?
(Apr-07-2019, 11:30 PM)micseydel Wrote: [ -> ]You probably want p1.pid; how is Python supposed to know you want p1 when you only reference Popen?
From that page I referenced:
Quote: Popen.pid

The process ID of the child process.

I guess one has to know the strange conventions they use.

Thanks, that works. Appreciate it.
POpen is a class. p1 is an instance of that class. POpen does not have a pid because it is not running. It would only be a strange convention if POpen did have a pid.
It may seem strange to you as a new programmer, but I've used several languages and they're all the same. Imagine if you created a p2 after the p1 - if you said Popen.pid, how would Python know which one to use?
Based on your questions here and the tkinter thread it looks you lack basic understanding of OOP (object-oriented programming) - e.g. classes, instances, attributes, etc. I would strongly advise to have a look at a introductory tutorial on this topic.
We have few tutorials on classes - https://python-forum.io/Thread-Classes-Class-Basics for start
but any decent tutorial would do
(Apr-08-2019, 07:06 AM)buran Wrote: [ -> ]Based on your questions here and the tkinter thread it looks you lack basic understanding of OOP (object-oriented programming) - e.g. classes, instances, attributes, etc. I would strongly advise to have a look at a introductory tutorial on this topic.
We have few tutorials on classes - https://python-forum.io/Thread-Classes-Class-Basics for start
but any decent tutorial would do

I tried to PM you but you have that disabled. Thanks for that link.