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

[BUG] "One instance of dooit is already running!" error #49

Closed
gilbh opened this issue Jun 28, 2022 · 16 comments
Closed

[BUG] "One instance of dooit is already running!" error #49

gilbh opened this issue Jun 28, 2022 · 16 comments
Labels
bug Something isn't working

Comments

@gilbh
Copy link

gilbh commented Jun 28, 2022

Hi,
This happens when I am try to run dooit.exe from the command line. Here's what I am getting:

C:\Users\gilbe\Envs\utils\Scripts>dooit.exe
One instance of dooit is already running!
Quiting...

Steps to reproduce the behavior:

  1. Open cmd
  2. Type dooit
  3. See error
  • OS: Windows
  • Version: 11

I ran the pip install from inside my envs (which is called Utils

Thanks!!

@gilbh gilbh added the bug Something isn't working label Jun 28, 2022
@TyBalduf
Copy link

Seems like this commit introduced the error e1d08b1

@kraanzu
Copy link
Member

kraanzu commented Jun 28, 2022

hey @gilbh, can you update and re-check if it's working now?

@TyBalduf
Copy link

TyBalduf commented Jun 28, 2022

@kraanzu I still have the same issue after updating (on Windows 10 machine). I did some debugging and it looks like PID = getpid() is getting the PID for python.exe rather than dooit.exe.

I think a simple fix would just be to check if you come across multiple dooit/dooit.exe processes. As long as there is only one (i.e. the one currently executing), it can run. Any more than one means there is already a dooit instance executing somewhere else on that machine.

Changing is_running to:

def is_running():
    PID = getpid()
    dooit_count = 0
    for process in psutil.process_iter():
        if process.name() in ["dooit", "dooit.exe"]:
            dooit_count += 1
        if dooit_count > 1:
            return True

    return False

Gets it past that routine, but this is followed by a number of other errors. I'll submit a separate issue and/or pull request.

@gilbh
Copy link
Author

gilbh commented Jun 28, 2022

Thanks.

Is there a new build to re-install and check? (I am novice in github etc ...) ... I tried running the source but I get:

(utils) C:\Users\gilbe\Envs\utils\Lib\site-packages\dooit>python __init__.py
Traceback (most recent call last):
  File "C:\Users\gilbe\Envs\utils\Lib\site-packages\dooit\__init__.py", line 2, in <module>
    from .ui.tui import Doit
ImportError: attempted relative import with no known parent package

@kraanzu
Copy link
Member

kraanzu commented Jun 29, 2022

Is there a new build to re-install and check?

Yes!

python init.py

No you are not supposed to do that...It won't work that way
Just run this:

python3 -m pip install git+https://github.com/kraanzu/dooit.git

@gilbh
Copy link
Author

gilbh commented Jun 29, 2022

Thank you!

I ran

python3 -m pip install git+https://github.com/kraanzu/dooit.git

-- and still got the same error. I then tried:

python3 -m pip install --force-reinstall git+https://github.com/kraanzu/dooit.git

-- and still got the error.

Please advise, with thanks.

@gilbh
Copy link
Author

gilbh commented Jun 29, 2022

I went now and check the code in __init__.py:

def is_running():
    PID = getpid()
    for process in psutil.process_iter():
        if process.name() in ["dooit", "dooit.exe"] and process.pid != PID:
            return True

    return False

I think this is the correct version, right? (process.name() in ["dooit", "dooit.exe"])

Still, when I run dooit.exe I get the same error.

@kraanzu
Copy link
Member

kraanzu commented Jun 29, 2022

This is strange... It means that you have yet another dooit.exe running. Guess I'll add a time difference check too :)

@TyBalduf
Copy link

@kraanzu I think he is having the same issue I describe. It's not that there are multiple dooit instances, it's that the PID you are comparing against is for python.exe not dooit.exe.

@kraanzu
Copy link
Member

kraanzu commented Jun 30, 2022

Hey @TyBalduf,

it's that the PID you are comparing against is for python.exe

Hmm, that seems strange. Since we are comparing both name and the pid, It shouldn't be the case ig.

Idk how windows does this but when I made a seperate test file to run dooit i get this:

psutil.Process(pid=79038, name='python', status='sleeping', started='08:53:27')

So the function should have returned False

@kraanzu
Copy link
Member

kraanzu commented Jun 30, 2022

Hey @gilbh ,
Can you check what's the output of this code:

from os import getpid
import psutil

PID = getpid()
for process in psutil.process_iter():
    if process.name() in ["dooit", "dooit.exe"] and process.pid != PID:
        print(process)

@TyBalduf
Copy link

@kraanzu

def is_running():
    PID = getpid()
    print(f"Initial PID: {PID}")
    for process in psutil.process_iter():
        print(process)
        if process.name() in ["dooit", "dooit.exe"] and process.pid != PID:
            return True
    return False

If I add these print statements to is_running, here is a (truncated) version of my output.

Initial PID: 33308
psutil.Process(pid=0, name='System Idle Process', status='running')
psutil.Process(pid=4, name='System', status='running')
psutil.Process(pid=104, name='', status='stopped', started='2022-06-20 23:22:10')
...
psutil.Process(pid=33308, name='python.exe', status='running', started='09:29:22')
...
psutil.Process(pid=39060, name='chrome.exe', status='running', started='09:19:51')
psutil.Process(pid=39472, name='dooit.exe', status='running', started='09:29:22')
One instance of dooit is already running!
Quiting...

So the if statement gets entered because it found process.name()==dooit.exe, but the initial PID its comparing against isn't for another instance of dooit.exe, but for python.exe, so naturally process.pid != PID.

I'm not sure how to ensure that getpid would give you the pid for dooit.exe, so I think just counting the number of dooit instances might work easier on all platforms.

@gilbh
Copy link
Author

gilbh commented Jun 30, 2022

Hey @gilbh , Can you check what's the output of this code:

from os import getpid
import psutil

PID = getpid()
for process in psutil.process_iter():
    if process.name() in ["dooit", "dooit.exe"] and process.pid != PID:
        print(process)

Here's the output for the above code, when I run dooit.exe:

psutil.Process(pid=3380, name='dooit.exe', status='running', started='09:56:48')

@kraanzu
Copy link
Member

kraanzu commented Jul 1, 2022

Sorry for the late reply, I am currently dealing with my semester final exams :(
Thanks a buch for debugging @TyBalduf

I think just counting the number of dooit instances might work easier on all platforms.

Yes this is much better. I'll push an update :)

@kraanzu
Copy link
Member

kraanzu commented Jul 1, 2022

Hey @gilbh , It should work as expected now :)

@kraanzu
Copy link
Member

kraanzu commented Mar 2, 2023

Sync implemented in v.1.0

@kraanzu kraanzu closed this as completed Mar 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants