LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 11-24-2016, 09:04 AM   #1
morganjeff7272
Member
 
Registered: Dec 2015
Location: Oklahoma City
Distribution: Ubuntu
Posts: 38
Blog Entries: 2

Rep: Reputation: Disabled
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.
 
Old 11-25-2016, 07:38 AM   #2
BW-userx
LQ Guru
 
Registered: Sep 2013
Location: Somewhere in my head.
Distribution: Slackware (current), FreeBSD, Win10, It varies
Posts: 9,952

Rep: Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148
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.

Last edited by BW-userx; 11-25-2016 at 07:43 AM.
 
Old 11-25-2016, 07:58 AM   #3
morganjeff7272
Member
 
Registered: Dec 2015
Location: Oklahoma City
Distribution: Ubuntu
Posts: 38

Original Poster
Blog Entries: 2

Rep: Reputation: Disabled
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....
 
Old 11-25-2016, 08:17 AM   #4
BW-userx
LQ Guru
 
Registered: Sep 2013
Location: Somewhere in my head.
Distribution: Slackware (current), FreeBSD, Win10, It varies
Posts: 9,952

Rep: Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148
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?

Last edited by BW-userx; 11-25-2016 at 08:28 AM.
 
Old 11-25-2016, 08:23 AM   #5
morganjeff7272
Member
 
Registered: Dec 2015
Location: Oklahoma City
Distribution: Ubuntu
Posts: 38

Original Poster
Blog Entries: 2

Rep: Reputation: Disabled
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????
 
Old 11-25-2016, 08:33 AM   #6
BW-userx
LQ Guru
 
Registered: Sep 2013
Location: Somewhere in my head.
Distribution: Slackware (current), FreeBSD, Win10, It varies
Posts: 9,952

Rep: Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148
Quote:
Originally Posted by morganjeff7272 View Post
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.

Last edited by BW-userx; 11-25-2016 at 08:36 AM.
 
Old 11-25-2016, 08:46 AM   #7
BW-userx
LQ Guru
 
Registered: Sep 2013
Location: Somewhere in my head.
Distribution: Slackware (current), FreeBSD, Win10, It varies
Posts: 9,952

Rep: Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148
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()

Last edited by BW-userx; 11-25-2016 at 08:47 AM.
 
Old 11-25-2016, 08:55 AM   #8
morganjeff7272
Member
 
Registered: Dec 2015
Location: Oklahoma City
Distribution: Ubuntu
Posts: 38

Original Poster
Blog Entries: 2

Rep: Reputation: Disabled
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???
 
Old 11-25-2016, 09:02 AM   #9
morganjeff7272
Member
 
Registered: Dec 2015
Location: Oklahoma City
Distribution: Ubuntu
Posts: 38

Original Poster
Blog Entries: 2

Rep: Reputation: Disabled
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
 
Old 11-25-2016, 09:04 AM   #10
BW-userx
LQ Guru
 
Registered: Sep 2013
Location: Somewhere in my head.
Distribution: Slackware (current), FreeBSD, Win10, It varies
Posts: 9,952

Rep: Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148
Quote:
Originally Posted by morganjeff7272 View Post
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.
 
Old 11-25-2016, 09:11 AM   #11
BW-userx
LQ Guru
 
Registered: Sep 2013
Location: Somewhere in my head.
Distribution: Slackware (current), FreeBSD, Win10, It varies
Posts: 9,952

Rep: Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148
calling its destructor function for example.
 
Old 11-25-2016, 09:16 AM   #12
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 16,216

Rep: Reputation: 5432Reputation: 5432Reputation: 5432Reputation: 5432Reputation: 5432Reputation: 5432Reputation: 5432Reputation: 5432Reputation: 5432Reputation: 5432Reputation: 5432
in python indenting cannot be ignored so please use [code]here comes your script[/code] tags to post your code.
 
Old 11-25-2016, 10:36 PM   #13
morganjeff7272
Member
 
Registered: Dec 2015
Location: Oklahoma City
Distribution: Ubuntu
Posts: 38

Original Poster
Blog Entries: 2

Rep: Reputation: Disabled
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....
 
Old 11-26-2016, 03:48 AM   #14
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 16,216

Rep: Reputation: 5432Reputation: 5432Reputation: 5432Reputation: 5432Reputation: 5432Reputation: 5432Reputation: 5432Reputation: 5432Reputation: 5432Reputation: 5432Reputation: 5432
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.
 
Old 11-26-2016, 08:23 AM   #15
BW-userx
LQ Guru
 
Registered: Sep 2013
Location: Somewhere in my head.
Distribution: Slackware (current), FreeBSD, Win10, It varies
Posts: 9,952

Rep: Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148
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.

Last edited by BW-userx; 11-26-2016 at 08:26 AM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Seek a python script through zabbix api to list hosts? 624867243@qq.com Linux - Server 3 02-27-2016 10:01 AM
python displaying list contents in scrollable window error bloodyscript Programming 2 09-25-2011 01:38 AM
Hung script as a result of bg process Poki Linux - Newbie 1 05-01-2009 05:01 PM
Shell script to check process and restart if "hung" georage Programming 5 10-29-2008 07:10 PM
killing a hung up process with a script lockejr Linux - General 2 04-13-2006 11:40 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 08:55 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration