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

sals.process cleanup/refactor #555

Merged
merged 123 commits into from
Mar 11, 2021
Merged

Conversation

sameh-farouk
Copy link
Member

@sameh-farouk sameh-farouk commented Jan 25, 2021

Description

sals.process cleanup/refactor

Changes

Related Issues

closes #467
#541
closes #557
closes #561

Decisions Needed:

Suggested changes below are not included in this PR for compatibility reasons with any old code.
but it may be considered, discussed, and make decisions about:

  • 1: kill(), check_start() and check_stop() functions return True when succeded. raise an exception otherwise.

    def kill(proc, sig=signal.SIGTERM, timeout=5, sure_kill=False):

    def check_start(cmd, filterstr, n_instances=1, retry=1):

    def check_stop(cmd, filterstr, retry=1, n_instances=0):

    • the returned True is redundant and not needed, it actually never return False. in case of the operation failed we raise an exception.

    Decision: the function should return None and the calling code should call the function inside try .. except, and never check for the output.

    Update: Solved, after discussion with @abom. now, these functions return None.

  • 2: kill_all() function default signal is SIGKILL and inconsistent with kill() function that have SIGTERM as a default signal also it almost have same functionality as kill_process_by_name() function.

    def kill_all(process_name, sig=signal.SIGKILL):

    Decision: kill_all() default signal should be re-considered also the function itself should be deprecated and removed in favor of kill_process_by_name() because they are almost the same.

    Update: Solved, after discussion with @abom. now, this function deprecated and removed in favor of kill_process_by_name()

  • 3: the module functions divided between functions that return the processes as a list[int] represents the processes ID(s) (due to it was initially parsing the PIDs from the ps shell command output), and functions that return the processes as psutil.Process objects. passing PIDs is not reliable in case the process is gone and its PID reused by another process, also this will affect the performance when we initiate the psutil.Process objects repeatedly from pids between function calls.

    • ex: we iterate through some psutil.Process objects in one function to do some work, when returning the function getting processes PIDs, appended it to a list, and send it to another function. the second function will again initiate a Process object to do its work. this affects the performance and may end with dealing with a different process than the intended one.

    Decision: as we now depend completely on psutil in this module, all functions should return psutil.Porcess objects instead of PIDs: list[int], another alternative, the affected functions - specially get_pids() - could take a parameter to decide whether it should return processes IDs or the Processes objects.

  • 4: is_port_listening() function is irrelevant in the process sal. it is already implemented in the nettools sal and should not re-implemented here.

    def is_port_listening(port, ipv6=False):

    Decision: the function should be deprecated and removed in favor of tcp_connection_test() from the nettools sal.

Checklist

  • Pre-commit hook is installed to do formatting checks before committing code...etc
  • Tests included
  • Build pass
  • Documentation
  • Code format and docstrings

- Matching google python docstring style
- Adding missing info for cwd arg
- Removing Redundant type check
- Updating the docstring, matching google style
- Update docstring to match google style
- simplify the code
- Fixing issue #557.
- Adding optional args timeout, sure_kill.
- dealing with edge cases and ensure proper error handling.
- updating the docstring.
- Adding new optional args limit, _alt_source
- Changing the default_predicate operator to equality instead of contain
- check against the exe and command basename not the  whole command path
- updating and restyling the docstring
- Restyling the docstring to match google style
- Catching psutil.AccessDenied error
- using new get_pids `limit` option
- removing redundant code and simplify the code
- Restyling the docstring to match google style
- Making use of  check_running()
- Adding proper error handling
- remove some make-no-sense code
- use psutil.Popen to execute the cmd for a better control of the executed
    subprocess
- Updating and restyling docstring
- Making use of check_running()
- Adding proper error handling
- remove some make-no-sense code
- use psutil.Popen to execute the cmd for a better control of the executed
    subprocess
- Updating and restyling docstring
- Adding proper error handler
- Use psutil.Popen for better control of the executed subprocess
- Updating the docstring and restyling it to match google style
- making use of get_pids() `limit` new option to make the function faster
- Updating the docstring
- making use of kill_process_by_name() due to the similarities.
- Updating the docstring
- Adding new optional args 'timeout' and 'sure_kill'
- Making use of kill() 'timeout' and 'sure_kill'
- Restyling the docstring
- getting rid of `ps` shell command replacing it with psutil
- updating the docstring
- Making use of nettools sal
- Adding support for ports bound to IPv6 localhost address using a new
    optional arg `ipv6`
- Updating the docstring
- Adding proper error handling
- Now it yields psutil.Process instead of retuning the pid(s) list
    for faster reusing between module functions and for consistency
    sake.
- Updating the docstring
- Adding proper error handling
- Now it Yielding the processes
- Updating the docstring
- Making use of kill() `sure_kil` new option
- Updating the docstring
- Adding proper error handling
- Updating the docstring
- renaming args to more readable names.
- Updating the docstring.
- Re-implementing the function to be more generic
- Adding new args `ipv6`, `udp`
- fix issue # 561
- Updating the docstring
- Adding optional args and supporting for `ipv6` and `udp`
- Making use of get_pid_by_port() new args `ipv6` and `udp`
- Making use of get_process_by_port() and its new args
- Making use of kill() new args `timeout` and `sure_kill`
jumpscale/sals/process/__init__.py Show resolved Hide resolved
jumpscale/sals/process/__init__.py Outdated Show resolved Hide resolved
jumpscale/sals/process/__init__.py Outdated Show resolved Hide resolved
jumpscale/sals/process/__init__.py Outdated Show resolved Hide resolved
jumpscale/sals/process/__init__.py Outdated Show resolved Hide resolved
jumpscale/sals/process/__init__.py Outdated Show resolved Hide resolved
jumpscale/sals/process/__init__.py Outdated Show resolved Hide resolved
jumpscale/sals/process/__init__.py Outdated Show resolved Hide resolved
jumpscale/sals/process/__init__.py Outdated Show resolved Hide resolved
jumpscale/sals/process/__init__.py Outdated Show resolved Hide resolved
@abom abom merged commit 9c51f70 into development Mar 11, 2021
@abom abom deleted the development_sal_process_iss467 branch March 11, 2021 09:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants