Click here to Skip to main content
15,070,511 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
        protocol = input()
        protocol = protocol.upper()
        protocol1_list = ["PROTOCOL 1", "PROTOCOL ONE", "INITIATE NEW GREETING" ]
        for i in protocol1_list:
            if i in protocol:
                rest of function

 def removeOldGreeting():
        protocol = input("")
        protocol = protocol.upper()
        protocol2_list = ["PROTOCOL 2", "PROTOCOL TWO", "INITIATE DELETE GREETING"]
        for i in protocol2_list:
            if i in protocol:
                rest of function

How would I make these two functions run together, wait for an input and when an input from one of the lists from one of the functions is typed in, only that function is ran and the other stops?

I've read about multiprocessing and I've used an if statement globally but I've realized that there will be many elif's because I want to check tens, if not hundreds of functions. I would just find it easier to read if it was in the function but then again it might be hard on the computer to run that many functions at the same time. Sorry if this is difficult to understand, I'm not very good at explaining things.

What I have tried:

I have tried to use if statements outside of the functions but I have found that there will have to be multiple elif's.
Updated 10-Aug-16 5:45am

1 solution

I don't get what you are actually willing to do. But form these lines said by you ,
"How would I make these two functions run together"
. I understand you are willing to implement Threading in your application.

Here is how you implement thread for two functions and will make the two functions run together.[Example]

#Python version 3.5.2
from threading import Thread

def function1():
    for i in range(100):
        print("Function 1 is executing")

def function2():
    for i in range(100):
        print("Function 2 is executing")

t = Thread(target=function1)
t1 = Thread(target=function2)

and the output will be like this
Function 2 is executingFunction 1 is executing

Function 2 is executingFunction 1 is executing


Function 2 is executingFunction 1 is executing

NOTE: Multi-threading satisfies your need but multi-threading is entirely different from multi-processing. This threaded application(shown in the example above) performs only a single task at a time. It is your CPU which allocates time for both the threads to run together., I mean time is divided and each task is performed. At a particular time only one thread will be executed. It looks like your program is performing multiple tasks at a same time but it is not.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900