here이라는 질문이 있는데 해결되었습니다.Python에서 스레딩 가능 클래스를 동적으로로드하는 중
나의 새로운 질문 dynmaically하여 디렉토리에있는 모듈로드를 통해 반복 할 마지막에 코드를 함께 할 수있다 : 나는 웹 사이트에서 PDF를 읽는하고있는 대부분의 클래스에서
modules = pkgutil.iter_modules(path=[os.path.join(path,'scrapers')])
for loader, mod_name, ispkg in modules:
# Ensure that module isn't already loaded, and that it isn't the parent class
if (mod_name not in sys.modules) and (mod_name != "Scrape_BASE"):
# Import module
loaded_mod = __import__('scrapers.'+mod_name, fromlist=[mod_name])
# Load class from imported module. Make sure the module and the class are named the same
class_name = mod_name
loaded_class = getattr(loaded_mod, class_name)
# only instantiate subclasses of Scrape_BASE
if(issubclass(loaded_class,Scrape_BASE.Scrape_BASE)):
# Create an instance of the class and run it
instance = loaded_class()
instance.start()
instance.join()
text = instance.GetText()
, 내용을 스크랩하고 GetText()에 의해 연속적으로 반환되는 텍스트를 설정합니다.
경우에 따라 PDF가 너무 커서 최종적으로 세그멘테이션 오류가 발생합니다. 스레드를 모니터링하여 3 분 정도 후에 스레드가 시간 초과되도록하는 방법이 있습니까? 누구든지이 구현하는 방법에 대한 제안이 있습니까?
많은 멋진 아이디어가 여기에 있습니다. 나는 그들이 나를 도울 수 있는지 살펴볼 것이다. –