강의

멘토링

커뮤니티

Inflearn Community Q&A

byeonghwijeong's profile image
byeonghwijeong

asked

Programming for Us: Intermediate Python (Inflearn Original)

AsyncIO Multi-Scraping Practice (1-2)

AsyncIO 멀티 스크랩핑 실습 예제 관련 질문

Written on

·

158

0

image.png

설명해주신 해당 코드에서는
ThreadPoolExecutor를 닫는 코드가 없던데
해당방식이면 메모리 누수가 발생할 가능성은없을까요???
with ThreadPoolExecutor(max_workers=max_workers) as executor:
이런식으로 with문을 활용해서 하는것이 좋지않나요?

pythondjango

Answer 1

0

niceman님의 프로필 이미지
niceman
Instructor

안녕하세요.

네 좋은질문입니다. 쓰레드는 작업이 된 후 상태값을 반환합니다. 쓰레드내에서 File I/O 작업등을 사용할 때 with를 사용하셔도 좋습니다.

메모리 누수문제는 고려하지 않아도 될 것 같아요.

파이썬 3.7, 3.8버전에서는 with문과 셧다운 메소드를 통해 중지시킬 수 있습니다

감사합니다.

from concurrent.futures import ThreadPoolExecutor

 

with ThreadPoolExecutor(max_workers=2) as executor:

executor.shutdown(wait=True)

byeonghwijeong's profile image
byeonghwijeong

asked

Ask a question