• 카테고리

    질문 & 답변
  • 세부 분야

    프로그래밍 언어

  • 해결 여부

    미해결

Thread synchronization(스레드 동기화) 관련

21.04.26 10:36 작성 조회수 114

0

안녕하세요 선생님. 동기화가 안되어서 Ending value가 2가 나오는 현상에 대해서 질문이 있습니다.

분명히 logging.info("Thread %s: finishing update", n)까지 실행이 3번되었는데 self.value가 3이 안나오는 이유가 궁금합니다.

수업에서 설명해주신거같은데 아직 이해가 잘 안된거같습니다. 동시에 함수가 실행되어서 나타나는 현상인가요?

답변 1

답변을 작성해보세요.

0

네 후반부에는 print문으로 출력해서 중간 결과를 확인하고 있습니다.

언급하신대로 출력이 되지 않을수도 있습니다.

If you are implementing asynchronous signal handlers using the signal module, you may not be able to use logging from within such handlers. This is because lock implementations in the threading module are not always re-entrant, and so cannot be invoked from such signal handlers.

또는 lock을 이용해서 출력도 가능합니다.

https://stackoverflow.com/questions/48745240/python-logging-in-multi-threads