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

Refactor the stop command #71

Merged
merged 7 commits into from
Dec 24, 2024
Merged

Conversation

SimonL22
Copy link
Contributor

@SimonL22 SimonL22 commented Sep 18, 2024

Now several subfunctions are factored out from the rather lengthy execute function, in particular for stopping a native binary and for stopping a container.

- try except block in extra function for more readability
- added return False if pinfo for an psutilprocess can't be created sucessfully (otherwise pinfo isn't defined for the next block)
- Linelenght <=79
check_stop_remove_container Funktion hinzugefügt um Code aus der execute auszulagern
Copy link
Member

@joka921 joka921 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tiny improvements.

from qlever.command import QleverCommand
from qlever.commands.status import StatusCommand
from qlever.containerize import Containerize
from qlever.log import log
from qlever.util import show_process_info


def try_to_kill(proc, pinfo):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Try to kill the given process, return true iff it was killed successfully. the process_info is used for logging.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Also add documentation for the other functions you extract).

src/qlever/commands/stop.py Show resolved Hide resolved
Comment on lines 97 to 100
if try_to_kill(proc, pinfo):
return True
else:
return False
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if try_to_kill(proc, pinfo):
return True
else:
return False
return try_to_kill(proc, pinfo)

log.info("")
show_process_info(proc, "", show_heading=True)
return False
return True
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the return is inside the try:clause, the code is much more readable.

return True


def check_stop_remove_container(server_container):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These two functions should have consistent names, e.g. stop_process and stop_container.

@joka921 joka921 changed the title Update stop.py Refactor the stop command Dec 24, 2024
@joka921 joka921 merged commit ddf751e into ad-freiburg:main Dec 24, 2024
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants