-
Notifications
You must be signed in to change notification settings - Fork 22
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
Keep the main script alive, threads with I/O #262
Comments
Unfortunately there isn't a method on the I'll look to add this as a feature request. However, let me give you a quick example that will unblock you in the near term. from crython.tab import CronTab
tab = CronTab(name='my-app')
# every 5 seconds
@tab.job(expr='*/5 * * * * * *')
def first_func():
logging.info("start 1st func")
time.sleep(3) # but this could sometimes take more than 5 seconds
logging.info("finish 1st func")
# every minute at seconds 1, 5 and 10
@tab.job(expr='1,5,10 * * * * * *')
def second_func():
logging.info("2nd func")
if __name__ == "__main__":
tab.start()
tab.join() The Hope that helps! |
Uhm @ahawker I've created a file called from crython.tab import CronTab
tab = CronTab(name='my-app')
# every 5 seconds
@tab.job(expr='*/5 * * * * * *')
def first_func():
logging.info("start 1st func")
time.sleep(3) # but this could sometimes take more than 5 seconds
logging.info("finish 1st func")
# every minute at seconds 1, 5 and 10
@tab.job(expr='1,5,10 * * * * * *')
def second_func():
logging.info("2nd func")
if __name__ == "__main__":
tab.start()
tab.join() then on the command line: $ python crontab_main.py
Traceback (most recent call last):
File "crontab_main.py", line 6, in <module>
@tab.job(expr='*/5 * * * * * *')
AttributeError: 'CronTab' object has no attribute 'job' I am using the latest release available: $ pip show crython
Name: crython
Version: 0.0.9
Summary: Lightweight task scheduler using cron expressions.
Home-page: https://github.com/ahawker/crython
Author: Andrew Hawker
Author-email: andrew.r.hawker@gmail.com
License: MIT
Location: /<PATH_TO_MY_CONDA_ENVIRONMENT>/Miniconda3/lib/python3.6/site-packages
Requires: I see you were working on this in a separate branch/PR Thanks :) |
@tappoz This should be available in version |
I've defined this example script
main_foo.py
which dies just after I execute it withpython main_foo.py
. If I enable that infinitewhile
loop currently commented out at the bottom of the following example, then I see the script staying alive and printing logging statements as expected.I have 2 questions:
while
loop the expected way to keep alive the script? I was expecting the library was taking care itself of keeping the script alive with some sort of blocking infinite loop and I was surprised I had to take care of it myself, so I am wondering if I am using it the right way or is there a recommended way to do this?first_func()
in the following example which could potentially take more time than the recurrence at which it is scheduled. If the code insidefirst_func()
is mainly network I/O (REST APIs) andnumpy
/pandas
calculations (done in native C), then I should be good to go withcrython
invoking it multiple times even if some old executions still have to complete. I am assumingcrython
is runningfirst_func()
in a separate thread at each match of the crontab string (e.g.'*/5 * * * * * *'
), so whenever thisfirst_func()
is finished the thread will die andcrython
will go on with no hiccups. Given that there is no CPU intensive code running in python (because the CPU intensive part is done in C), then I shouldn't be blocking the main thread of the main process, right? With this setup I should not mess with the GIL, I think.The text was updated successfully, but these errors were encountered: