Skip to content

Instantly share code, notes, and snippets.

@4383
Last active May 4, 2019 16:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 4383/6b8160c1db5dae411ec91ba505d27cfe to your computer and use it in GitHub Desktop.
Save 4383/6b8160c1db5dae411ec91ba505d27cfe to your computer and use it in GitHub Desktop.
Test padding implementation
threads = [
"",
"1111111111111-thread1-base ",
"1111111111111-thread2-base ",
"1111111111111-thread3-very-long ",
"1111111111111-short ",
"1111111111111-thread4-base ",
"1111111111111-thread3-very-long-long ",
"1111111111111-short ",
"1111111111111-thread5-base ",
"",
"1111111111111-thread6-base ",
]
tasks = [
"time {}line task1",
"time {}call task2",
"time {}line task3",
]
class Test:
def __init__(self):
self.padding = 0
def set_padding(self, thread_info):
current_thread_len = len(thread_info)
self.padding = max(self.padding, current_thread_len)
return thread_info.ljust(self.padding)
def trace(self):
for thread in threads:
for line in tasks:
print(line.format(self.set_padding(thread)))
if __name__ == "__main__":
test = Test()
test.trace()
@4383
Copy link
Author

4383 commented May 4, 2019

Will output:

time line task1
time call task2
time line task3
time 1111111111111-thread1-base line task1
time 1111111111111-thread1-base call task2
time 1111111111111-thread1-base line task3
time 1111111111111-thread2-base line task1
time 1111111111111-thread2-base call task2
time 1111111111111-thread2-base line task3
time 1111111111111-thread3-very-long line task1
time 1111111111111-thread3-very-long call task2
time 1111111111111-thread3-very-long line task3
time 1111111111111-short             line task1
time 1111111111111-short             call task2
time 1111111111111-short             line task3
time 1111111111111-thread4-base      line task1
time 1111111111111-thread4-base      call task2
time 1111111111111-thread4-base      line task3
time 1111111111111-thread3-very-long-long line task1
time 1111111111111-thread3-very-long-long call task2
time 1111111111111-thread3-very-long-long line task3
time 1111111111111-short                  line task1
time 1111111111111-short                  call task2
time 1111111111111-short                  line task3
time 1111111111111-thread5-base           line task1
time 1111111111111-thread5-base           call task2
time 1111111111111-thread5-base           line task3
time                                      line task1
time                                      call task2
time                                      line task3
time 1111111111111-thread6-base           line task1
time 1111111111111-thread6-base           call task2
time 1111111111111-thread6-base           line task3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment