python error: The "freeze_support()" line can be omitted if the program is not going to be frozen to produce an executable.

2020. 3. 17. 12:30·Error code 모음/4. Python errors
반응형

위 에러는 multiprocessing 을 실행할 때, 

if __name__ == '__main__':  과 freeze_support( ) 를 사용하지 않고 실행했을 때 

나타나는 에러이다.

 

우선 if __name__ == '__main__' 의 경우에는 이미 실행된 함수가 

다른 객체에 할당되어 실행될때, 이전의 내용과 중복되어 실행되는 것을 막아주는 기능을 하는데

중복/반복을 막아 자원이 중복 사용되는 것을 막아주는 함수이다.

 

그리고 freeze_support( ) 의 경우에는 파이썬 multiprocessing 이 윈도우에서 실행될 경우, 자원이 부족할 경우를 대비해

파일 실행을 위한 자원을 추가해주는 역할을 하는 함수이다

 

그리고 효율 적인 자원 사용과 중복 방지를 위하여

if __name__ =='__main__' 과  freeze_support( ) 함수를 사용하라는 이야기이다

 

위 에러를 해결한 예제문은 이렇다

 

import multiprocessing as mp
from multiprocessing import freeze_support # freeze_support 함수 임포트

def washer(dishes, output):

    for dish in dishes:
        print("Washing", dish, 'dish')
        output.put(dish)

def dryer(input):
    while True:
        dish = input.get()
        print('Drying',dish,'dish')
        input.task_done()

if __name__ == '__main__':   # 중복 방지를 위한 사용
    freeze_support()         # 윈도우에서 파이썬이 자원을 효율적으로 사용하게 만들어준다.
    dish_queue = mp.JoinableQueue()
    dryer_proc = mp.Process(target = dryer, args = (dish_queue,))
    dryer_proc.daemon = True
    dryer_proc.start()
    dishes = ['salad','bread','entree','dessert']
    washer(dishes, dish_queue)
    dish_queue.join()

일단..이렇게 이해는 하고 사용은 했는데..시간이 지날 수록 이해하는 것도 바뀌고

틀린 내용이 있을 수 있다..

 

만약에 내용이 틀릴 경우에는 댓글로...!!

 

참고 링크

https://stackoverflow.com/questions/42522113/python-3-multiprocessing-same-function-with-different-args

 

Python 3 - Multiprocessing same function with different args

In python 3, I am trying to run the same function with multiple arguments at the same time. I am using multiprocessing in Python 3.5.2, Anaconda 4.1.1 (64-bit), in Windows 7. I am getting the follo...

stackoverflow.com

https://kite.com/python/docs/multiprocessing.freeze_support

 

Code Faster with Kite - AI Autocomplete & Docs for Python

Kite is a free AI-powered autocomplete for Python developers. Works 100% locally. Code faster with Kite's plugin for your editor, featuring Intelligent Snippets and Python docs.

kite.com

https://docs.python.org/ko/3/library/multiprocessing.html

 

multiprocessing — 프로세스 기반 병렬 처리 — Python 3.8.2 문서

multiprocessing 은 threading 모듈과 유사한 API를 사용하여 프로세스 스포닝(spawning)을 지원하는 패키지입니다. multiprocessing 패키지는 지역과 원격 동시성을 모두 제공하며 스레드 대신 서브 프로세스를 사용하여 전역 인터프리터 록 을 효과적으로 피합니다. 이것 때문에, multiprocessing 모듈은 프로그래머가 주어진 기계에서 다중 프로세서를 최대한 활용할 수 있게 합니다. 유닉스와 윈도우에서 모두 실행됩니다

docs.python.org

https://stackoverflow.com/search?q=The+%22freeze_support%28%29%22+line+can+be+omitted+if+the+program+is+not+going+to+be+frozen+to+produce+an+executable.

 

Human verification

Stack Overflow | The World’s Largest Online Community for Developers

stackoverflow.com

 

반응형

'Error code 모음 > 4. Python errors' 카테고리의 다른 글

python error: Could not import the lzma module. Your installed Python is incomplete.  (0) 2020.04.08
python error: do_this( ) takes 1 positional argument but 15 were given  (0) 2020.03.18
python error L “TypeError: __str__ returned non-string” but still prints to output?  (0) 2020.03.07
python error : __init__() missing 1 required positional argument:  (0) 2020.03.07
파이썬 에러 : 'tuple' object has no attribute 'get'  (0) 2020.03.04
'Error code 모음/4. Python errors' 카테고리의 다른 글
  • python error: Could not import the lzma module. Your installed Python is incomplete.
  • python error: do_this( ) takes 1 positional argument but 15 were given
  • python error L “TypeError: __str__ returned non-string” but still prints to output?
  • python error : __init__() missing 1 required positional argument:
쟈누
쟈누
Ad astra per aspera
    반응형
  • 쟈누
    쟈누의 기록공간
    쟈누
  • 전체
    오늘
    어제
    • 분류 전체보기 (444)
      • AWS (31)
        • Glue (4)
        • S3 (1)
      • 클라우드 (0)
      • Data Engineering (37)
        • GitHub (10)
        • NiFi (11)
        • Spark (10)
        • Snowflake (0)
        • 머신러닝, AI (6)
      • 언어 (118)
        • 데이터 베이스 (42)
        • JAVA (9)
        • Python (34)
        • Java Script (15)
        • Linux (18)
      • 프로젝트, 인강 그리고 책 (30)
        • Spotify Project (7)
        • RASA chatbot Project (9)
        • Naver shopping Project (6)
        • 빅데이터를 지탱하는 기술 (8)
      • OLD (56)
        • IT 용어 사전 (13)
        • Front End (12)
        • Back End (31)
      • Error code 모음 (165)
        • 1. SQL errors (17)
        • 2. Hadoop errors (20)
        • 3. Linux Errors (14)
        • 4. Python errors (33)
        • 5. JAVA, Spring errors (41)
        • 6. Jav Script errors (10)
        • 7. Dev Tools errors (9)
        • 8. Git errors (8)
        • 9. Jenkins Errors (4)
        • 10. airflow Errors (2)
        • 11. Aws errors (7)
      • 개인 (1)
        • 책 (1)
  • 블로그 메뉴

    • 홈
    • 태그
    • 방명록
    • 블로그 관리
    • 글쓰기
  • 링크

  • 공지사항

    • 간단한 블로그 소개
  • 인기 글

  • 태그

    linux
    json
    install
    파이썬
    API
    Git
    SQL
    NiFi
    MySQL
    java
    Spring
    에러
    node
    AWS
    Python
    리눅스
    자바
    error
    python error
    설치
  • 최근 댓글

  • 최근 글

  • hELLO· Designed By정상우.v4.10.3
쟈누
python error: The "freeze_support()" line can be omitted if the program is not going to be frozen to produce an executable.
상단으로

티스토리툴바