Created
March 3, 2020 14:40
-
-
Save jangsoopark/75aa7873056cb6548dc0af3cd141a433 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import threading | |
import random | |
import time | |
import sys | |
import os | |
class ASDFException(BaseException): | |
def __init__(self, msg): | |
super(ASDFException, self).__init__() | |
self.msg = msg | |
def __str__(self): | |
return self.msg | |
class asdf(threading.Thread): | |
def __init__(self, _id): | |
super(asdf, self).__init__() | |
self.trials = 0 | |
self._id = _id | |
def run(self): | |
i = 0 | |
while True: | |
try: | |
print('id : %d step : %d' % (self._id, i)) | |
time.sleep(self._id * random.randint(1, 10)) | |
raise KeyError('id : %d' % self._id) | |
except BaseException as e: | |
self.trials += 1 | |
print('%s trials %d' % (e, self.trials)) | |
if self.trials == 5: | |
os._exit(-1) | |
if __name__ == '__main__': | |
eee = [] | |
try: | |
for i in range(5): | |
eee.append(asdf(i + 1)) | |
eee[i].start() | |
except ASDFException as e: | |
print(e) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment