0

For some application that I am building, I have the need to schedule another Python script (or more generally, a shell script) to run immediately or later, but after I exit the current Python script. How do I achieve this? I looked through the sched module and other suggestions for similar (not same) applications discussed elsewhere on this forum. But none of them seem to satisfy my requirement. Basically what I need to do is the following (have stripped out a lot of unnecessary code in my application):

from flask import Flask, request, redirect  
def incoming_msg():
    attr_1 = request.values.get('some_attribute', None)
    attr_2 = request.values.get('another_attribute', None)

    # Schedule another Python script (or a scell script) to run immediately after  
    # exiting this function or at a certain time (calculated thru attr_1 and attr_2)
    # This new script will need to be passed parameters attr_1 and attr_2

    return

I am using a MAC platform.

sachinsdesai
  • 47
  • 1
  • 7
  • Are you running on *ix, or on Windows? On *ix, you could simply invoke `cron`. On Windows, you could find similar [options](https://stackoverflow.com/questions/132971/what-is-the-windows-version-of-cron), but knowing which OS to answer to will help everyone. I'm sure you've seen https://stackoverflow.com/questions/373335/how-do-i-get-a-cron-like-scheduler-in-python ? – Scott Mermelstein Feb 26 '18 at 18:11
  • Scott, I am on a MAC and using Python 3.6 – sachinsdesai Feb 26 '18 at 21:31
  • Have you considered having the subprocess handle the delay? I.e. always spawn the subprocess immediately, and use an additional param indicating how much it should delay by. For the actual delay you could use sleep or SIGALRM. – 1.618 Feb 26 '18 at 21:41

1 Answers1

1

You should look into Python Advanced Sheduler. It is a very powerful tool to shedule python function execution either based on a cron like shedule or based on other triggers (time delayed, recurring). A good starting point to verify your exact use case would be here

quantumbyte
  • 319
  • 1
  • 5