Utku
Utku

Reputation: 31

Multiprocessing with Schedule in Python

I trying combine these two codes. I wanna it to run in two different loops.

For example If I don't write an entry at the scheduled time, it must print "Good Luck for Test". I want the scheduled task to act independently.

import schedule 

import time 

def good_luck(): 

    print("Good Luck for Test") 

schedule.every().day.at("00:00").do(good_luck)

while True: 

    schedule.run_pending() 

    time.sleep(1) 

and


def assistant():

    command = input('input: ')

    if command == '1':

        print('is it one')

    else:

        print('is not one')    

while True:

    assistant()

Example output


Good Luck for Test #automatically at specified times
input: 1
is it one
input: 2
is not one
Good Luck for Test #automatically at specified times
Good Luck for Test #automatically at specified times
Good Luck for Test #automatically at specified times

etc.

Upvotes: 1

Views: 2619

Answers (1)

RightmireM
RightmireM

Reputation: 2492

The multiprocessing Python module may work. You may need to modify your method of input, however, to get the expected results.

import schedule 
import time 
import multiprocessing

def good_luck():
#    schedule.every().day.at("00:00").do(good_luck)
    schedule.every(1).minutes.do(_good_luck)
    while True: 
        schedule.run_pending() 
        time.sleep(1) 

def _good_luck(): 
    print("Good Luck for Test") 


def assistant():
    while True: 
        command = input('input: ')
        if command == '1':
            print('is it one')
        elif command.lower() == 'quit':
            return
        else:
            print('is not one')    

if __name__ == '__main__':
    jobs = []
    p1 = multiprocessing.Process(target=good_luck)
    jobs.append(p1)
    p1.start()
    assistant()

Upvotes: 1

Related Questions