old_contents: import multiprocessing, sys, datetime
  
  print_lock = multiprocessing.Lock()
  def safeprint(content):
    with print_lock:
      sys.stdout.write(("[" + str(multiprocessing.current_process().pid) + "] " + datetime.datetime.now().strftime('%H%M%S') + ": " + str(content) + '\r\n'))
  
new_contents: import multiprocessing, sys, datetime
  
  print_lock = multiprocessing.RLock()
  def safeprint(content):
    string = "[" + str(multiprocessing.current_process().pid) + "] " + datetime.datetime.now().strftime('%H%M%S') + ": " + str(content) + '\r\n'
    with print_lock:
      sys.stdout.write(string)
  
subject: Reduce the amount of time locking