1
def value(startH,startM,stopH,stopM):

        def job():
                do job 

        def job1():
                do another job


        start_time = "{0:02d}:{1:02d}".format(startH, startM)
        stop_time = "{0:02d}:{1:02d}".format(stopH, stopM)

        schedule.every().day.at(start_time).do(job)
        schedule.every().day.at(stop_time).do(job1)

        while True:
                schedule.run_pending()
                time.sleep(1)

Here startH, startM, stopH,stopM means starting hour,starting minute, stopping hour, and stopping minute. which is the input given by the user through android. This code runs. It runs onces and then it keeps running. Here is the suitation. If i want the user to input the time again. It wont accept. How can accept the input from the user while the loop is still running?lets just say the first task says to turn on the light then the second task is turning off the light. So when second task is done. It is assumed as complete.I tried using break, return. It does not work as it is supposed to.

public void publish(int startH,int startM, int stopH, int stopM )
{
    JSONObject js = new JSONObject();
    try {
        js.put("START_HOUR", startH);
        js.put("START_MINUTE", startM);
        js.put("STOP_HOUR", stopH);
        js.put("STOP_MINUTE", stopM);



    }


public void setTime(View view)
{


    int storeStartHour = Integer.parseInt(startHrs.getText().toString());
    int storeStartMinutes = Integer.parseInt(startMinutes.getText().toString());
    int storeStopHour = Integer.parseInt(stopHrs.getText().toString());
    int storeStopMinutes = Integer.parseInt(stopMinutes.getText().toString());



     publish(storeStartHour, storeStartMinutes, storeStopHour, storeStopMinutes);



}
6
  • It's called threading for instance. That or asynchronous/non-blocking code. I see no user input here tho do don't know where I would put it for you. Commented Mar 28, 2016 at 10:58
  • @Torxed the input from the android is stored in startH which is starting hour and startM which is starting minute and so on for stopH and stopM...it can be set once. Then i cant set is again... Commented Mar 28, 2016 at 11:01
  • Yea you need to show us the block of code that loops the user input as well because as of now all we can do is thread this function to be non-blocking. And that might cause issues. Commented Mar 28, 2016 at 11:04
  • by code meaning ? it is just simple in android part. user is able to input data only. they got text field to put input and a button to send that all data when pressed Commented Mar 28, 2016 at 11:11
  • @Torxed. i didnot actually get what you meant. But what i am trying to do is get the input from the user from android. say the user wants to put "12:40" as starting time.then startH will hold "12" and startM will hold "40". and same is the stopping time.public void publish(int startH,int startM, int stopH, int stopM ) { JSONObject js = new JSONObject(); try { js.put("START_HOUR", startH); js.put("START_MINUTE", startM); js.put("STOP_HOUR", stopH); js.put("STOP_MINUTE", stopM); } the message is sent in json Commented Mar 28, 2016 at 13:16

1 Answer 1

1

You can use threading.

Here's a very simple example:

import threading import time

def worker(num):
    # Do some stuff
    for i in range(5):
        time.sleep(2)
        print(2**(num + i))

if __name__ == "__main__":
    i = int(input("Enter a number: "))

    t = threading.Thread(target=worker, args=(i,)) # Always put a comma after the arguments. Even if you have only one arg.
    t.start() # Start the thread

    while True:
        choice = input()

        if choice == "stop":
            print("Waiting for the function to finish...")
            t.join() # Stop the thread (NOTE: the program will wait for the function to finish)
            break

        else:
            print(choice)

You can still input stuff while the worker is generating numbers.
Unless you really have to, don't print in the worker function since stdout can get messy.

Sign up to request clarification or add additional context in comments.

3 Comments

thank you for the example. But what i am trying to do is get the input from the user from android. say the user wants to put "12:40" as starting time.then startH will hold "12" and startM will hold "40". and same is the stopping time. I want the user to be able to add the input from the android not from the python interface. Do you have any ideas. I m stuck in this process
@sam Please explain in more detail. Are you running the script on andoid?
there is a ui.the user is able to input 4 value.startM, startH and stopH stopM. user inputs the value and clicks the button.then it is sent to raspberry in json object format which is intepreted by python. and that value is kept on the python code

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.