Miksus / rocketry

Modern scheduling library for Python
https://rocketry.readthedocs.io
MIT License
3.25k stars 105 forks source link

BUG multilaunch process spams Terminate #144

Closed egisxxegis closed 1 year ago

egisxxegis commented 1 year ago

Describe the bug Log gets spammed with status:terminate messages. This bug exists for tasks, that are running on process and using multilaunch=True.

To Reproduce

  1. Copy paste code (I will add it to the bottom of issue)
  2. Use newest version of Rocketry (multilaunch=True is needed)
  3. Run code: python my_file_name.py
  4. Wait 30 seconds
  5. Check logs file

Expected behavior

  1. Terminate should not be called if task has done job with status:success
  2. If terminate gets called, I think it should terminate task only once (not every 0.1s)

Screenshots Uploading screenshot of logs image

Desktop (please complete the following information):

Additional context Here I paste the code


from datetime import timedelta
from time import sleep

from rocketry import Rocketry
from rocketry.log import TaskLogRecord
from redbird.repos import CSVFileRepo

# #
# Rocketry app
repo = CSVFileRepo(filename="check_me_after_30_seconds.csv", model=TaskLogRecord)
app = Rocketry(
    config={
        "task_execution": "async",
        "max_process_count": 4,
        "timeout": timedelta(seconds=30),
    },
    logger_repo=repo,
)

# #
# tasks
@app.task("every 10 seconds")
async def mark_10_seconds():
    print("10 seconds have passed")

@app.task(execution="process")
async def run_me_sir():
    print("Sir, I am going to sleep for 20 seconds")
    sleep(20)
    print("Sir, I am done with sleeping")

@app.task(execution="process", multilaunch=True)
async def run_multilaunch_me_madam():
    print("Madam, I as multilaunch am going to sleep for 20 seconds")
    sleep(20)
    print("Madam, I as multilaunch am done with sleeping")

if __name__ == "__main__":
    app.session["run_me_sir"].run()
    app.session["run_multilaunch_me_madam"].run()
    app.run()
Miksus commented 1 year ago

Sorry for taking quite a long to get to this issue. Thanks for spotting!

Indeed something odd is going on there. I suppose the run is never cleaned off or something. I'll investigate this further.

Was thinking of doing the next release but I don't think I'll release it before this is sorted out. Thanks again for spotting :)