# ProcessSalesOrder.py # Standard Modules import subprocess import sys import os # we can use open() and change stdout to a txt file import datetime # subprocess page 71 ## SalesOrder -> Customer ## WordOrder -> Work to be done by us 12 secs ## PurchaseOrder -> The supplies need to do the job 4 secs # Process starts 0 # prep 2 secs # subprocesses start 2 ## sp1 4 sec ## sp2 12 # all subprocessed end 14 # cleanup 3 secs # Process ends 17 secs # Process def sales_order(): print("Processing sales order...") # all the processes for this step work_order_subprocess = subprocess.Popen( [ sys.executable, '-c', 'from ProcessSalesOrder import work_order; work_order()' ] ) # Popen() purchase_order_subprocess = subprocess.Popen( [ sys.executable, '-c', 'from ProcessSalesOrder import purchase_order; purchase_order()' ] ) # Popen() # Wait for all subprocesses to end, before the end of the main process ends print("Waiting for work order subprocess to finish....") work_order_subprocess.wait() # 4 secs print("Waiting for purchase order subprocess to finish....") purchase_order_subprocess.wait() # 12 secs print("Now the main process will continue, now that the subprocesses have finished...") print("Then the main process exits...") # subprocess def work_order(): print("Processing work order...") # all the processes for this step #subprocess def purchase_order(): print("Processing purchase order...") # all the processes for this step def main(): # redirect stdout to a file so that when we call print().stdout log_stamp = datetime.datetime.now().strftime('%Y%m%d_%H%M%S') log_filename = "process_logging_" + log_stamp + ".txt" # join param obj # changes stdout from terminal(__stdout__) to a .txt in the os sys.stdout = open(log_filename, 'w') # other stuff happens print(log_filename) sales_order() # Main function process to call # print() -> outputting to the log file # close the open() sys.stdout.close() # change stdout back to __stdout__ (terminal) sys.stdout = sys.__stdout__ # main statement -> main exec for a module # entrypoint of your application if __name__ == "__main__": # page 35 main()