Script in python... hung window gui.. not in process list
Linux - SoftwareThis 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
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Introduction to Linux - A Hands on Guide
This guide was created as an overview of the Linux Operating System, geared toward new users as an exploration tour and getting started guide, with exercises at the end of each chapter.
For more advanced trainees it can be a desktop reference, and a collection of the base knowledge needed to proceed with system and network administration. This book contains many real life examples derived from the author's experience as a Linux system and network administrator, trainer and consultant. They hope these examples will help you to get a better understanding of the Linux system and that you feel encouraged to try out things on your own.
Click Here to receive this Complete Guide absolutely free.
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.
Distribution: Slackware (current), FreeBSD, Win10, It varies
Posts: 9,952
Rep:
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.
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....
Distribution: Slackware (current), FreeBSD, Win10, It varies
Posts: 9,952
Rep:
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?
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????
Distribution: Slackware (current), FreeBSD, Win10, It varies
Posts: 9,952
Rep:
Quote:
Originally Posted by morganjeff7272
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.
Distribution: Slackware (current), FreeBSD, Win10, It varies
Posts: 9,952
Rep:
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()
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
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
Distribution: Slackware (current), FreeBSD, Win10, It varies
Posts: 9,952
Rep:
Quote:
Originally Posted by morganjeff7272
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.
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....
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.
Distribution: Slackware (current), FreeBSD, Win10, It varies
Posts: 9,952
Rep:
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.