■ Popen 클래스의 poll 메소드를 사용해 자식 프로세스를 폴링하는 방법을 보여준다.
▶ 예제 코드 (PY)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
import datetime import subprocess popen = subprocess.Popen(["sleep", "0.00001"]) while popen.poll() is None: print("작업중...") print(datetime.datetime.now()) print("종료 상태", popen.poll()) """ 작업중... 2024-06-04 20:05:01.251376 작업중... 2024-06-04 20:05:01.251404 작업중... 2024-06-04 20:05:01.251409 작업중... 2024-06-04 20:05:01.251412 작업중... 2024-06-04 20:05:01.251417 작업중... 2024-06-04 20:05:01.251432 작업중... 2024-06-04 20:05:01.251443 작업중... 2024-06-04 20:05:01.251452 작업중... 2024-06-04 20:05:01.251456 작업중... 2024-06-04 20:05:01.251459 작업중... 2024-06-04 20:05:01.251461 작업중... 2024-06-04 20:05:01.251470 작업중... 2024-06-04 20:05:01.251475 작업중... 2024-06-04 20:05:01.251478 작업중... 2024-06-04 20:05:01.251481 작업중... 2024-06-04 20:05:01.251492 작업중... 2024-06-04 20:05:01.251501 작업중... 2024-06-04 20:05:01.251512 작업중... 2024-06-04 20:05:01.251531 작업중... 2024-06-04 20:05:01.251535 작업중... 2024-06-04 20:05:01.251539 작업중... 2024-06-04 20:05:01.251543 작업중... 2024-06-04 20:05:01.251546 작업중... 2024-06-04 20:05:01.251549 작업중... 2024-06-04 20:05:01.251557 작업중... 2024-06-04 20:05:01.251562 작업중... 2024-06-04 20:05:01.251565 작업중... 2024-06-04 20:05:01.251568 작업중... 2024-06-04 20:05:01.251577 작업중... 2024-06-04 20:05:01.251592 작업중... 2024-06-04 20:05:01.251596 작업중... 2024-06-04 20:05:01.251600 작업중... 2024-06-04 20:05:01.251603 작업중... 2024-06-04 20:05:01.251607 작업중... 2024-06-04 20:05:01.251615 작업중... 2024-06-04 20:05:01.251630 작업중... 2024-06-04 20:05:01.251634 작업중... 2024-06-04 20:05:01.251643 작업중... 2024-06-04 20:05:01.251653 종료 상태 0 """ |