Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Where is Popen.pid?
#1
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
Reply
#2
You probably want p1.pid; how is Python supposed to know you want p1 when you only reference Popen?
Reply
#3
(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.
Reply
#4
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.
Reply
#5
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?
Reply
#6
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
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#7
(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.
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020