Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

psutil can't detect chrome processes from inside python script on Ubuntu #2436

Open
AdilMughal2126 opened this issue Aug 24, 2024 · 0 comments

Comments

@AdilMughal2126
Copy link

AdilMughal2126 commented Aug 24, 2024

Summary

  • OS: { Ubuntu }
  • Architecture: { 64bit }
  • Psutil version: { 6.0.0 }
  • Python version: { 3.12.4 }
  • Type: { performance, scripts }

Description

The following script is working fine for Windows but for Ubuntu, it only works on Python shell. When I ran the code inside my Python script it did not detect chrome processes (I am using a virtual environment). After searching and posting questions on StackOverflow I didn't get any answers so I think this might be an issue with psutil. I am using seleniumbase on AWS ec2 with Ubuntu AMI.

def kill_processes():
    print('Process killing started...')
    proc_list = []
    for proc in psutil.process_iter():
        if "chrome" in proc.name().lower() or "uc_driver" in proc.name().lower():
            proc_list.append(proc)
            proc.terminate()
            print(proc)
            time.sleep(1)  # Adjust timing as needed
            if proc.is_running():
                proc.kill()
    gone, alive = psutil.wait_procs(
        proc_list, timeout=3)  # Adjust timing as needed
    for proc in alive:
        proc.kill()

    print('Process killing ends...')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant