Giter Site home page Giter Site logo

bmwant / hapless Goto Github PK

View Code? Open in Web Editor NEW
97.0 4.0 4.0 236 KB

Run and manage background processes

Home Page: https://bmwant.link/hapless-easily-run-and-manage-background-processes/

Python 98.86% Makefile 1.14%
background-jobs cli process-manager runner ukraine python jobs python3 script automation

hapless's Introduction

hapless

Checks PyPI PyPI - Python Version

Code style: black Ruff EditorConfig pre-commit

hapless (adjective) - (especially of a person) unfortunate. A developer who accidentally launched long-running process in the foreground.

Simplest way of running and tracking processes in the background.

asciicast

Installation

$ pip install hapless

# or to make sure proper pip is used for the given python executable
$ python -m pip install hapless

Install into user-specific directory in case of any permissions-related issues.

$ pip install --user hapless
$ python -m pip install --user hapless

Usage

# Run arbitrary script
$ hap run -- python long_running.py

# Show summary table
$ hap

# Display status of the specific process
$ hap status 1

See USAGE.md for the complete list of commands and available parameters.

Contribute

See DEVELOP.md to setup your local development environment and feel free to create a pull request with a new feature.

Releases

See CHANGELOG.md for the new features included within each release.

See also

  • Rich console UI library.
  • Supervisor full-fledged process manager.
  • podmena provides nice emoji icons to commit messages.

Support πŸ‡ΊπŸ‡¦ Ukraine in the war!

πŸ‡ΊπŸ‡¦ Donate to this foundation in case you want to help. Every donation matter!

hapless's People

Contributors

bmwant avatar github-actions[bot] avatar imotai avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

hapless's Issues

How to Remove the Failed Processes/Only keep the running ones?

Hi, thank you for this great package.

May I ask can we remove/clear the failed processes, but only display the running ones, when using hap?

I have this question because, after killed and restarted the scripts, all the historical processes (failed/success/running) will be displayed on the hat status interface. However, we do not need to check the status of failed(i.e. killed) ones.

Can we only display the running ones through hat? Are there any options of it?

Thank you so much!

Hapless in zsh, doesn't inherit shell

I have a zsh function that I store in .zshrc, my shell is zsh.
When I try to run my function, I get the following error:
/bin/sh: somezshfunction: command not found

$ hap clean
🧲 Deleted 4 finished haps

$ hap status
🧲 No haps are currently running

$ hap run 'somezshfunction'
🧲 Launching hap ⚑️1 (hap-tp9g3w)

$ hap status
┏━━━━┯━━━━━━━━━━━━┯━━━━━━━┯━━━━━━━━━━┯━━━━━┯━━━━━━━━━━┓
┃ #  β”‚ Name       β”‚ PID   β”‚ Status   β”‚  RC β”‚  Runtime ┃
┠────┼────────────┼───────┼──────────┼─────┼──────────┨
┃ 1  β”‚ hap-tp9g3w β”‚ 66805 β”‚ β€’ failed β”‚ 127 β”‚ a moment ┃
┗━━━━┷━━━━━━━━━━━━┷━━━━━━━┷━━━━━━━━━━┷━━━━━┷━━━━━━━━━━┛

$ hap logs --stderr hap-tp9g3w
/bin/sh: somezshfunction: command not found

$ set | grep -i shell
SHELL=/bin/zsh

I tried to include it in the command to use zsh, but same error:

 $ hap logs --stderr hap-213nam
/bin/sh: zsh -c 'somezshfunction': command not found

Is there a way to make this work or set hapless to use zsh?

Read from $PATH for commands to run

I have the tye, an executable. type tye gives me this: /home/user/.dotnet/tools/tye.

Moving this to /usr/bin/ will not work. Tye which needs dependencies which are stored in dotnet/tools. But when I do hap run tye, I get the error: /bin/sh: 1: tye not found`.

But dotnet/tools is in my PATH. So I think Hapless should include the local path as well when running commands?

Q. can we run python script and pass arguments as well?

hey, not issue, but question/query. is it possible to run hapless python script with arguments.

my current python script run blender with a script, which take input arguments. is it possible to run this script with hapless and pass arguments..

command = ['blender', '-P', 'gp_remote.py', '--', '--payload_file', payload_file]

License of this Project

Hi,

Thanks for this amazing project! It looks very promising and I want to slightly extend/modify some parts to fit my need.

I am wondering about the license for this project. Is it allowed if I use part of it in my project?

Best regards,
Xiaozhe

How run Hapless with python 3 scripts?

First, thanks for creating this nice tool! It's really useful for my workflow.

However, lately literally all python processes uses python 3 as interpreter. For example, when I want to use to run Django server I usually use the command: python manage.py runserver.

This works fine. But with hap: hap run --check python manage.py runserver gives me the error:

🧲 Hap exited too quickly. stderr message:
  File "manage.py", line 17
    ) from exc
         ^
SyntaxError: invalid syntax

Any suggestions to let this work with python 3 scripts?

hap status errors out despite no running processes, uninstalling/reinstalling doesn't work, affects all environments

This is the error output when running hap

Traceback (most recent call last): File "/home/<user>/.pyenv/versions/3.11.0/envs/sandbox311/bin/hap", line 8, in <module> sys.exit(cli()) ^^^^^ File "/home/<user>.pyenv/versions/3.11.0/envs/sandbox311/lib/python3.11/site-packages/click/core.py", line 1157, in __call__ return self.main(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/<user>/.pyenv/versions/3.11.0/envs/sandbox311/lib/python3.11/site-packages/click/core.py", line 1078, in main rv = self.invoke(ctx) ^^^^^^^^^^^^^^^^ File "/home/<user>/.pyenv/versions/3.11.0/envs/sandbox311/lib/python3.11/site-packages/click/core.py", line 1666, in invoke rv = super().invoke(ctx) ^^^^^^^^^^^^^^^^^^^ File "/home/<user>/.pyenv/versions/3.11.0/envs/sandbox311/lib/python3.11/site-packages/click/core.py", line 1434, in invoke return ctx.invoke(self.callback, **ctx.params) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/<user>/.pyenv/versions/3.11.0/envs/sandbox311/lib/python3.11/site-packages/click/core.py", line 783, in invoke return __callback(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/<user>.pyenv/versions/3.11.0/envs/sandbox311/lib/python3.11/site-packages/click/decorators.py", line 33, in new_func return f(get_current_context(), *args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/<user>/.pyenv/versions/3.11.0/envs/sandbox311/lib/python3.11/site-packages/hapless/cli.py", line 38, in cli _status(None, verbose=verbose) File "/home/<user>/.pyenv/versions/3.11.0/envs/sandbox311/lib/python3.11/site-packages/hapless/cli.py", line 61, in _status hapless.stats(haps, verbose=verbose) File "/home/<user>/.pyenv/versions/3.11.0/envs/sandbox311/lib/python3.11/site-packages/hapless/main.py", line 73, in stats status_text = Hapless._get_status_text(hap.status) ^^^^^^^^^^ File "/home/<user>/.pyenv/versions/3.11.0/envs/sandbox311/lib/python3.11/site-packages/hapless/hap.py", line 121, in status if self.rc != 0: ^^^^^^^ File "/home/<user>/.pyenv/versions/3.11.0/envs/sandbox311/lib/python3.11/site-packages/hapless/utils.py", line 28, in wrapper return func(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^ File "/home/<user>/.pyenv/versions/3.11.0/envs/sandbox311/lib/python3.11/site-packages/hapless/hap.py", line 143, in rc return int(f.read()) ^^^^^^^^^^^^^ ValueError: invalid literal for int() with base 10: ''

[Bug] AttributeError: module 'os' has no attribute 'fork'

When running

hap run py .\while_test.py

Python version: 3.10.8
Hap version: 0.1.6

Traceback (most recent call last):
  File "C:\Users\caeden\AppData\Local\Programs\Python\Python310\lib\runpy.py", line 196, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "C:\Users\caeden\AppData\Local\Programs\Python\Python310\lib\runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "C:\Users\caeden\AppData\Local\Programs\Python\Python310\Scripts\hap.exe\__main__.py", line 7, in <module>
  File "C:\Users\caeden\AppData\Local\Programs\Python\Python310\lib\site-packages\click\core.py", line 1130, in __call__
    return self.main(*args, **kwargs)
  File "C:\Users\caeden\AppData\Local\Programs\Python\Python310\lib\site-packages\click\core.py", line 1055, in main
    rv = self.invoke(ctx)
  File "C:\Users\caeden\AppData\Local\Programs\Python\Python310\lib\site-packages\click\core.py", line 1657, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "C:\Users\caeden\AppData\Local\Programs\Python\Python310\lib\site-packages\click\core.py", line 1404, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "C:\Users\caeden\AppData\Local\Programs\Python\Python310\lib\site-packages\click\core.py", line 760, in invoke
    return __callback(*args, **kwargs)
  File "C:\Users\caeden\AppData\Local\Programs\Python\Python310\lib\site-packages\hapless\cli.py", line 101, in run
    hapless.run(cmd_escaped, name=name, check=check)
  File "C:\Users\caeden\AppData\Local\Programs\Python\Python310\lib\site-packages\hapless\main.py", line 253, in run
    pid = os.fork()
AttributeError: module 'os' has no attribute 'fork'
PS C:\Users\caeden\Github\hap-test> hap run py .\while_test.py
Traceback (most recent call last):
  File "C:\Users\caeden\AppData\Local\Programs\Python\Python310\lib\runpy.py", line 196, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "C:\Users\caeden\AppData\Local\Programs\Python\Python310\lib\runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "C:\Users\caeden\AppData\Local\Programs\Python\Python310\Scripts\hap.exe\__main__.py", line 7, in <module>
  File "C:\Users\caeden\AppData\Local\Programs\Python\Python310\lib\site-packages\click\core.py", line 1130, in __call__
    return self.main(*args, **kwargs)
  File "C:\Users\caeden\AppData\Local\Programs\Python\Python310\lib\site-packages\click\core.py", line 1055, in main
    rv = self.invoke(ctx)
  File "C:\Users\caeden\AppData\Local\Programs\Python\Python310\lib\site-packages\click\core.py", line 1657, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "C:\Users\caeden\AppData\Local\Programs\Python\Python310\lib\site-packages\click\core.py", line 1404, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "C:\Users\caeden\AppData\Local\Programs\Python\Python310\lib\site-packages\click\core.py", line 760, in invoke
    return __callback(*args, **kwargs)
  File "C:\Users\caeden\AppData\Local\Programs\Python\Python310\lib\site-packages\hapless\cli.py", line 101, in run
    hapless.run(cmd_escaped, name=name, check=check)
  File "C:\Users\caeden\AppData\Local\Programs\Python\Python310\lib\site-packages\hapless\main.py", line 253, in run
    pid = os.fork()
AttributeError: module 'os' has no attribute 'fork'

Seems like an issue because I'm using it on windows

Hapless doesn't seem to actually kill the background task

Step 1: Create a background task using hapless.

image

Step 2: Hapless shows it as running.

image

Step 3: Checking the processes with ps shows three distinct processes for the task. The pid reported by hapless seems to be the second in the list from ps.

image

When I attempt to kill the task all but the last of the processes from ps seem to be killed, which leaves the task running even though hapless reports that it isn't running.

image

Specificy a custom aliases for process?

Personally when I run a process in the background, I find the the aliases assigned by Hapless, like hap-17pqkr or something, not very obvious. When I run multiple processes, I can be easily lost to figure out which process I need to inspect.

Would it be possible to assign a alias name for it like: hap --aliases docker run docker-compose-up ?

(By the way: stay strong in UkraΓ―ne, slava Ukraini!)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.