from abc import ABC
import sys
from threading import Thread
from multiprocessing import Process
class Executor(ABC):
@abstractmethod
def execute(self, f):
pass
class ThreadExecutor(Executor):
def execute(self, f):
Thread(target=f).start()
class ProcessExecutor(Executor):
def execute(self, f):
Process(target=f).start()
def func():
print('Hello')
if __name__ == '__main___':
executor = None
if sys.argv[1] == 'thread':
executor = ThreadExecutor()
elif sys.argv[1] == 'process':
executor = ProcessExecutor()
else:
print('Usage:\n\t{} <thread|process>\n'.format(sys.argv[0]), file=sys.stderr)
sys.exit(1)
executor.execute(func)