Код: Выделить всё
class TestClass:
def __init__(self, secondsToSleepFor):
self.secondsToSleepFor = secondsToSleepFor
def testMethodToExecInParallel(self):
print("ThreadName: " + threading.currentThread().getName())
print(threading.currentThread().getName() + " is sleeping for " + str(self.secondsToSleepFor) + " seconds")
time.sleep(self.secondsToSleepFor)
print(threading.currentThread().getName() + " has finished!!")
with concurrent.futures.ThreadPoolExecutor(max_workers = 2) as executor:
futuresList = []
print("before try")
try:
testClass = TestClass(3)
future = executor.submit(testClass.testMethodToExecInParallel)
futuresList.append(future)
except Exception as exc:
print('Exception generated: %s' % exc)
Но если я допущу ошибку, например указав неправильное количество параметров в «testMethodToExecInParallel», например:< /p>
Код: Выделить всё
def testMethodToExecInParallel(self, secondsToSleepFor):
Код: Выделить всё
future = executor.submit(testClass.testMethodToExecInParallel)
Код: Выделить всё
def testMethodToExecInParallel(self):
print("ThreadName: " + threading.currentThread().getName())
print("self.secondsToSleepFor: " + self.secondsToSleepFor)
Подробнее здесь: [url]https://stackoverflow.com/questions/54777947/concurrent-futures-threadpoolexecutor-doesnt-print-errors[/url]
Мобильная версия