import multiprocessing, sys
from datetime import datetime
from common import settings

print_lock = multiprocessing.RLock()


def safeprint(msg, verbosity=0):
    """Prints in a thread-lock, taking a single object as an argument"""
    string = ("[" + str(multiprocessing.current_process().pid) + "] " +
              datetime.now().strftime('%H:%M:%S: ') + str(msg) + '\r\n')
    with print_lock:
        with open("output.txt", "a") as log:
            log.write(string)
        if settings.config.get('verbose') >= verbosity:
            sys.stdout.write(string)

import multiprocessing, sys
from datetime import datetime
from common import settings

print_lock = multiprocessing.RLock()
max_digits = 0

def safeprint(msg, verbosity=0):
    """Prints in a thread-lock, taking a single object as an argument"""
    pid = str(multiprocessing.current_process().pid)
    max_digits = max(max_digits, len(pid))
    pid = pid.zfill(max_digits)
    string = ("[" + pid + "] " + datetime.now().strftime('%H:%M:%S: ') +
              str(msg) + '\n')
    with print_lock:
        with open("output.txt", "a") as log:
            log.write(string)
        if settings.config.get('verbose') >= verbosity:
            sys.stdout.write(string)

Make thread marker consistent length
Make thread marker consistent length
  import multiprocessing, sys
  from datetime import datetime
  from common import settings
  
  print_lock = multiprocessing.RLock()
- 
+ max_digits = 0
  
  def safeprint(msg, verbosity=0):
      """Prints in a thread-lock, taking a single object as an argument"""
-     string = ("[" + str(multiprocessing.current_process().pid) + "] " +
+     pid = str(multiprocessing.current_process().pid)
-               datetime.now().strftime('%H:%M:%S: ') + str(msg) + '\r\n')
+     max_digits = max(max_digits, len(pid))
+     pid = pid.zfill(max_digits)
+     string = ("[" + pid + "] " + datetime.now().strftime('%H:%M:%S: ') +
+               str(msg) + '\n')
      with print_lock:
          with open("output.txt", "a") as log:
              log.write(string)
          if settings.config.get('verbose') >= verbosity:
              sys.stdout.write(string)
  
Make thread marker consistent length
## Code Before:
import multiprocessing, sys
from datetime import datetime
from common import settings

print_lock = multiprocessing.RLock()


def safeprint(msg, verbosity=0):
    """Prints in a thread-lock, taking a single object as an argument"""
    string = ("[" + str(multiprocessing.current_process().pid) + "] " +
              datetime.now().strftime('%H:%M:%S: ') + str(msg) + '\r\n')
    with print_lock:
        with open("output.txt", "a") as log:
            log.write(string)
        if settings.config.get('verbose') >= verbosity:
            sys.stdout.write(string)

## Instruction:
Make thread marker consistent length
## Code After:
import multiprocessing, sys
from datetime import datetime
from common import settings

print_lock = multiprocessing.RLock()
max_digits = 0

def safeprint(msg, verbosity=0):
    """Prints in a thread-lock, taking a single object as an argument"""
    pid = str(multiprocessing.current_process().pid)
    max_digits = max(max_digits, len(pid))
    pid = pid.zfill(max_digits)
    string = ("[" + pid + "] " + datetime.now().strftime('%H:%M:%S: ') +
              str(msg) + '\n')
    with print_lock:
        with open("output.txt", "a") as log:
            log.write(string)
        if settings.config.get('verbose') >= verbosity:
            sys.stdout.write(string)
