LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   Script in python... hung window gui.. not in process list (https://www.linuxquestions.org/questions/linux-software-2/script-in-python-hung-window-gui-not-in-process-list-4175594175/)

morganjeff7272 11-24-2016 09:04 AM

Script in python... hung window gui.. not in process list
 
So I have a looping program in python...
Basically...
Opens chromium driver, opens url, logs in, changes url, opens a different page waits 30 minutes, kills chromium driver, then kills any chromium-browse tasks.
then does it again.

Occasionally after leaving the box alone for 6-8 hours Ill find
orphaned or hung window gui not in process list so I can not figure out how to kill them and why this is happening.

I am running bodhi linux.

BW-userx 11-25-2016 07:38 AM

no code to go by, but, I'd say you'd have to code something to check for PID's connected to anything chromium, then kill them in the proper order. You know it creates a new child each time, so yeah, check its PID to be sure it is killed before creating another child. else kill it, then create another child. one could call it, baby killer code. :D

morganjeff7272 11-25-2016 07:58 AM

def kill(p_name):
"""Returns False if p_name is found and can't be killed
Returns True if p_name is not found
Returns True if p_name is found and killed"""
ret = True
for p in psutil.process_iter():
if(p.name() == p_name):
"""Friendly Kill"""
p.terminate()
for p in psutil.process_iter():
if(p.name() == p_name):
"""Force Kill"""
p.kill()
for p in psutil.process_iter():
if(p.name() == p_name):
"""Still Found in Process Running"""
ret = False
return ret

Then in a seperate class and .py file i call
if true process.exists('chromium-browse')
try
process.kill('chromium-browse')
catch Exception
pass

the only reason I am catching an exception here is sometimes the true statement above is wrong somehow and the pid never returns from the kill command and throws an exception.
Anyway so when the process is hung what is happening is there is no processes left for chromium but the window GUI is still hung on the gnome GUI and I try killing it with the x in the right hand upper corner and sometimes that works but sometimes it does not. Then I have to reboot....

BW-userx 11-25-2016 08:17 AM

I do not know python, but programming is programming, balickly.. if my logic is correct, or wait for someone that knows python.

Code:

def kill(p_name):
"""Returns False if p_name is found and can't be killed
  Returns True if p_name is not found
  Returns True if p_name is found and killed"""

ret = True

for p in psutil.process_iter():
      if(p.name() == p_name):
      """Friendly Kill"""
            p.terminate()

for p in psutil.process_iter():
      if(p.name() == p_name):
      """Force Kill"""
          p.kill()

for p in psutil.process_iter():
        if(p.name() == p_name):
    """Still Found in Process Running"""
 


ret = False
return ret
#could you also not write it like this instead?
return false
else
return true




your last test is checking to see if it is still running, if yes then return false, leaving it running. is that not a correct statement? if yes, then why are you not trying to kill it again?

morganjeff7272 11-25-2016 08:23 AM

I posted code so you could see the code of the killing process.
You stated to "I'd say you'd have to code something to check for PID's connected to anything chromium"
I replied "there is nothing left of the Chromium processes"
you replied "if My logic is correct"

Any way so the basic question is The window GUI "Graphical User Interface showing up in the gnome display is orphaned. There is no process attached to it. How do I kill the window????

BW-userx 11-25-2016 08:33 AM

Quote:

Originally Posted by morganjeff7272 (Post 5634413)
I posted code so you could see the code of the killing process.
You stated to "I'd say you'd have to code something to check for PID's connected to anything chromium"
I replied "there is nothing left of the Chromium processes"
you replied "if My logic is correct"

Any way so the basic question is The window GUI "Graphical User Interface showing up in the gnome display is orphaned. There is no process attached to it. How do I kill the window????

Oh I see, I think I am gathering what you are now talking about. the window "Chromium" on your desktop is still there. a redraw function comes to mind. seeing that it is leaving a "empty" window within your main window. (desktop).

moded: or perhaps somewhere within the Chromium window itself you may need to access its object to find a property that you can get to that calls to kill that window itself.

I too modded my first response, questioning your logic in that last test you have in that code.

BW-userx 11-25-2016 08:46 AM

thinking about this some more, can you call a killall function also?
in your last test where you check, if still running change it to false, (which is backwards logic? )

write something like this instead

Code:

for p in psutil.process_iter():
        if(p.name() == p_name):
    """Still Found in Process Running"""
        p.killall()


morganjeff7272 11-25-2016 08:55 AM

Code:

def kill(p_name):
"""Returns False if p_name is found and can't be killed
  Returns True if p_name is not found
  Returns True if p_name is found and killed"""

ret = True  # Return True IF nothing is done Stating that No processes were found IE: they have been killed

for p in psutil.process_iter():
      if(p.name() == p_name):
      """Friendly Kill"""
            p.terminate() # This tries to kill using default kill command

for p in psutil.process_iter():
      if(p.name() == p_name):
      """Force Kill"""
          p.kill() # This is a forced kill

for p in psutil.process_iter():
        if(p.name() == p_name):
    """Still Found in Process Running"""  # this will return false if name is still found in process list, So yes here I could add code If needed to
                                          #reiterate through the kill process.

 


ret = False
return ret
#could you also not write it like this instead?
return false
else
return true

You said something about redraw or moded???

morganjeff7272 11-25-2016 09:02 AM

something about how the psutil functions work Is why I wrote it the way I did.
I just wrapped it into something I can use that tries to friendly kill then deadly kill, which is probably where it is orphaning the window.
Ill recode it tonight with a 30 second wait between two friendly kills and gosh forbid if it still exists recurse back into the function

BW-userx 11-25-2016 09:04 AM

Quote:

Originally Posted by morganjeff7272 (Post 5634425)
Code:

def kill(p_name):
"""Returns False if p_name is found and can't be killed
  Returns True if p_name is not found
  Returns True if p_name is found and killed"""

ret = True  # Return True IF nothing is done Stating that No processes were found IE: they have been killed

for p in psutil.process_iter():
      if(p.name() == p_name):
      """Friendly Kill"""
            p.terminate() # This tries to kill using default kill command

for p in psutil.process_iter():
      if(p.name() == p_name):
      """Force Kill"""
          p.kill() # This is a forced kill

for p in psutil.process_iter():
        if(p.name() == p_name):
    """Still Found in Process Running"""  # this will return false if name is still found in process list, So yes here I could add code If needed to
                                          #reiterate through the kill process.

 


ret = False
return ret
#could you also not write it like this instead?
return false
else
return true

You said something about redraw or moded???

it looks like what maybe taking place here is that you are killing the process, but that kill is not calling to kill that window attached to the "backend" process that it is calling to kill, therefore the window itself it not getting removed, redraw to clear it, all depends on whatever a function that is called redraw within chromium handles redrawing if in fact it even has a function call called redraw.

nevertheless, when the process is called to be killed, it obliviously is not getting passed to the window itself to be kill along with the process attached to it. Therefore, if it is object ( orientated ), then hopefully their is within that object for the window itself a property you can get to that you can call to have that window be taken out of circulation as well.

you'd or I or we'd have to go look at the properties of that object in the chromium code, if they provide such information. or search though all of that code.

BW-userx 11-25-2016 09:11 AM

calling its destructor function for example.

pan64 11-25-2016 09:16 AM

in python indenting cannot be ignored so please use [code]here comes your script[/code] tags to post your code.

morganjeff7272 11-25-2016 10:36 PM

So.... I made some changes yesterday that I did not think would matter....
used to be
Code:

def Main
  kill process selenium driver chromium
  kill process chromium-browser
  start driver chromium
  open url
  the rest of it
  wait 30 minutes
  main

That above is definitely not exact syntax but it is what I am doing in a nut shell this morning I changed it to...
Code:

def main
  while True
      body()

def body
  kill process selenium driver chromium
  kill process chromium-browser
  start driver chromium
  open url
  the rest of it
  wait 30 minutes

I restarted system to get clean slate. Came home from work 8 hours later.... No orphaned windows.
Maybe the recursive call on main was too much so this way it finishes a function then calls it again....

pan64 11-26-2016 03:48 AM

recursive call may be a problem, but 8 hours means 16 level or recursion (because of "wait 30 minutes"), that cannot cause any problem.
From the other hand you need to check/handle the error messages generated by your python script. Probably you will get an idea.

BW-userx 11-26-2016 08:23 AM

can I ask if you still have this bit of code in there somewhere too?

Code:

for p in psutil.process_iter():
        if(p.name() == p_name):
    """Still Found in Process Running"""  # this will return false if name is still found in process list, So yes here I could add code If needed to
                                          #reiterate through the kill process.
 

ret = False
return ret

because to me that reads if one is still running you set it to false then return it false, even though it is true. Because of the test states if one is still running then set ret = false then returns that value(false).

I am not knowing how Python uses their code blocks not seeing any open and close brackets. Nor do know if python lets one use empty, then do nothing, if statements.

one would actually have to sit want watch it within at least an hours time to see how it actually works, or come back within a five minute time frame before and after it should execute every 30 minutes to send that kill command to see how long them windows stay open. Perhaps even check the return value from that last statement. Logically it should still read true because one is still active.

but if what you showed in your last post, replaces everything you showed before hand then my point is diffidently mute.


All times are GMT -5. The time now is 03:37 PM.