Microsoft MVP성태의 닷넷 이야기
개발 환경 구성: 601. PyCharm - 다중 프로세스 디버깅 방법 [링크 복사], [링크+제목 복사],
조회: 14613
글쓴 사람
정성태 (techsharer at outlook.com)
홈페이지
첨부 파일
 

(시리즈 글이 11개 있습니다.)
개발 환경 구성: 592. JetBrains의 IDE(예를 들어, PyCharm)에서 Visual Studio 키보드 매핑 적용
; https://www.sysnet.pe.kr/2/0/12752

개발 환경 구성: 595. PyCharm - WSL과 연동해 Django App을 윈도우에서 리눅스 대상으로 개발
; https://www.sysnet.pe.kr/2/0/12773

개발 환경 구성: 597. PyCharm - 윈도우 환경에서 WSL을 이용해 파이썬 앱 개발/디버깅하는 방법
; https://www.sysnet.pe.kr/2/0/12789

개발 환경 구성: 598. PyCharm - 원격 프로세스를 디버그하는 방법
; https://www.sysnet.pe.kr/2/0/12798

개발 환경 구성: 599. PyCharm - (반대로) 원격 프로세스가 PyCharm에 디버그 연결하는 방법
; https://www.sysnet.pe.kr/2/0/12800

개발 환경 구성: 601. PyCharm - 다중 프로세스 디버깅 방법
; https://www.sysnet.pe.kr/2/0/12806

스크립트: 26. 파이썬 - PyCharm을 이용한 fork 디버그 방법
; https://www.sysnet.pe.kr/2/0/12823

개발 환경 구성: 603. GoLand - WSL 환경과 연동
; https://www.sysnet.pe.kr/2/0/12825

개발 환경 구성: 673. JetBrains IDE에서 "Squash Commits..." 메뉴가 비활성화된 경우
; https://www.sysnet.pe.kr/2/0/13318

개발 환경 구성: 679. PyCharm(을 비롯해 JetBrains에 속한 여타) IDE에서 내부 Window들의 탭이 없어진 경우
; https://www.sysnet.pe.kr/2/0/13369

개발 환경 구성: 697. GoLand에서 ldflags 지정 방법
; https://www.sysnet.pe.kr/2/0/13489




PyCharm - 다중 프로세스 디버깅 방법

이클립스 IDE에 익숙하신 분은 아마 감각적으로 아실 수 있는 내용인데요, 반면 Visual Studio에 익숙한 경우라면 이걸 잘 모르실 수도 있을 듯합니다.

테스트를 위해 PyCharm에서 "Pure Python" 유형으로 프로젝트를 하나 생성하고 내부에 2개의 py 파일을 넣어두겠습니다.

# server_sock.py

import socket

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind(('127.0.0.1', 18080))
s.listen(5)

while True:
    clientSock, clientAddress = s.accept()
    readData = clientSock.recv(1024)
    if not readData:
        continue

    text = readData.decode()
    if text == 'quit':
        break

    print('Client sent:', clientAddress, text)

    clientSock.close()

# client_sock.py

import socket

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect(("127.0.0.1", 18080))

s.send('test'.encode())

s.close()

이런 경우, 비주얼 스튜디오라면 2개의 프로젝트를 생성한 것과 유사하게 볼 수 있습니다. 즉 server_sock.py를 서버 소켓이 있는 프로젝트 하나로, client_sock.py를 클라이언트 소켓을 구현한 프로젝트가 됩니다.

이런 경우, 테스트를 위해 대개의 경우 2개 모두 실행해야 합니다. 이럴 때 간단하게 사용할 수 있는 방법이, 그냥 편집 화면에서 (우선 server_sock.py 먼저) 마우스 우클릭을 해 "Run (server_sock)" 또는 "Debug (server_sock)" 메뉴를 선택하는 것입니다. 아래는 s.listen에 BP(BreakPoint)를 걸고 서버 소켓을 디버그 모드로 실행하는 것을 보여줍니다.

pycharm_multi_debug_1.png

그럼 하단에 "Debug" 창이 뜨면서 "server_sock" 탭이 하나 생성되고 s.listen에 BP를 걸었으므로 실행이 멈추게 됩니다. 더 실행을 하려면 "Run" / "Debugging Actions" / "Resume Program"을 선택합니다. (참고로 "Resume Program" 메뉴에 단축키가 없으므로 새로 지정해 두면 편합니다. 제 경우에는 F6 키로 등록해 두었습니다. ^^)

비주얼 스튜디오에서는 이렇게 한 번 디버그 모드로 진입하면 이후 다시 다른 프로젝트를 디버그로 시작하는 방법이 없습니다. (대신 애당초 다중 프로젝트 디버깅을 할 대상을 선택해 두어야 합니다.)

하지만, PyCharm의 경우에는 이 상태에서 다시 client_sock.py 파일을 열어 서버에서 했던 것과 마찬가지로 마우스 우클릭을 해 "Run (client_sock)" 또는 "Debug (client_sock)" 메뉴를 선택할 수 있습니다.

이렇게 얼마든지 다중 프로세스를 실행/디버깅할 수 있어 나름 상당히 편리합니다. ^^ 게다가, 저렇게 마우스를 이용한 우클릭 메뉴로 시작하면 그대로 "Run/Debug Configuration"로 보관까지 해주므로,

pycharm_multi_debug_2.png

복잡하게 "Edit Configurations..."을 이용해 추가할 필요도 없습니다.




[이 글에 대해서 여러분들과 의견을 공유하고 싶습니다. 틀리거나 미흡한 부분 또는 의문 사항이 있으시면 언제든 댓글 남겨주십시오.]







[최초 등록일: ]
[최종 수정일: 8/24/2021]

Creative Commons License
이 저작물은 크리에이티브 커먼즈 코리아 저작자표시-비영리-변경금지 2.0 대한민국 라이센스에 따라 이용하실 수 있습니다.
by SeongTae Jeong, mailto:techsharer at outlook.com

비밀번호

댓글 작성자
 




... 76  77  78  79  80  81  [82]  83  84  85  86  87  88  89  90  ...
NoWriterDateCnt.TitleFile(s)
11887정성태5/8/201921486.NET Framework: 829. C# - yield 문을 사용할 수 있는 메서드의 조건
11886정성태5/7/201919288오류 유형: 534. mstest.exe 실행 시 "Visual Studio Enterprise is required to execute the test." 오류 [2]
11885정성태5/7/201916226오류 유형: 533. mstest.exe 실행 시 "File extension specified '.loadtest' is not a valid test extension." 오류 발생
11884정성태5/5/201921028.NET Framework: 828. C# DLL에서 Win32 C/C++처럼 dllexport 함수를 제공하는 방법 - 두 번째 이야기
11883정성태5/3/201926214.NET Framework: 827. C# - 인터넷 시간 서버로부터 받은 시간을 윈도우에 적용하는 방법파일 다운로드1
11882정성태5/2/201922503.NET Framework: 826. (번역글) .NET Internals Cookbook Part 11 - Various C# riddles파일 다운로드1
11881정성태4/28/201922620오류 유형: 532. .NET Core 프로젝트로 마이그레이션 시 "CS0579 Duplicate 'System.Reflection.AssemblyCompanyAttribute' attribute" 오류 발생
11880정성태4/25/201918466오류 유형: 531. 이벤트 로그 오류 - Task Scheduling Error: m->NextScheduledSPRetry 1547, m->NextScheduledEvent 1547
11879정성태4/24/201926859.NET Framework: 825. (번역글) .NET Internals Cookbook Part 10 - Threads, Tasks, asynchronous code and others파일 다운로드2
11878정성태4/22/201922623.NET Framework: 824. (번역글) .NET Internals Cookbook Part 9 - Finalizers, queues, card tables and other GC stuff파일 다운로드1
11877정성태4/22/201922718.NET Framework: 823. (번역글) .NET Internals Cookbook Part 8 - C# gotchas파일 다운로드1
11876정성태4/21/201921733.NET Framework: 822. (번역글) .NET Internals Cookbook Part 7 - Word tearing, locking and others파일 다운로드1
11875정성태4/21/201922758오류 유형: 530. Visual Studo에서 .NET Core 프로젝트를 열 때 "One or more errors occurred." 오류 발생
11874정성태4/20/201922945.NET Framework: 821. (번역글) .NET Internals Cookbook Part 6 - Object internals파일 다운로드1
11873정성태4/19/201921456.NET Framework: 820. (번역글) .NET Internals Cookbook Part 5 - Methods, parameters, modifiers파일 다운로드1
11872정성태4/17/201922316.NET Framework: 819. (번역글) .NET Internals Cookbook Part 4 - Type members파일 다운로드1
11871정성태4/16/201920930.NET Framework: 818. (번역글) .NET Internals Cookbook Part 3 - Initialization tricks [3]파일 다운로드1
11870정성태4/16/201919213.NET Framework: 817. Process.Start로 실행한 콘솔 프로그램의 출력 결과를 얻는 방법파일 다운로드1
11869정성태4/15/201925046.NET Framework: 816. (번역글) .NET Internals Cookbook Part 2 - GC-related things [2]파일 다운로드2
11868정성태4/15/201921035.NET Framework: 815. CER(Constrained Execution Region)이란?파일 다운로드1
11867정성태4/15/201920196.NET Framework: 814. Critical Finalizer와 SafeHandle의 사용 의미파일 다운로드1
11866정성태4/9/201923319Windows: 159. 네트워크 공유 폴더(net use)에 대한 인증 정보는 언제까지 유효할까요?
11865정성태4/9/201919075오류 유형: 529. 제어판 - C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Administrative Tools is not accessible.
11864정성태4/9/201917831오류 유형: 528. '...' could be '0': this does not adhere to the specification for the function '...'
11863정성태4/9/201917706디버깅 기술: 127. windbg - .NET x64 EXE의 EntryPoint
11862정성태4/7/201920186개발 환경 구성: 437. .NET EXE의 ASLR 기능을 끄는 방법
... 76  77  78  79  80  81  [82]  83  84  85  86  87  88  89  90  ...