| 786 | |
| 787 | |
| 788 | def _wait_and_collect_mem(process): |
| 789 | # We only know how to collect memory on mac/linux. |
| 790 | if platform.system() == 'Darwin': |
| 791 | get_memory = _get_memory_with_ps |
| 792 | elif platform.system() == 'Linux': |
| 793 | get_memory = _get_memory_with_ps |
| 794 | else: |
| 795 | raise ValueError( |
| 796 | "Can't collect memory for process on platform %s." |
| 797 | % platform.system() |
| 798 | ) |
| 799 | memory = [] |
| 800 | while process.poll() is None: |
| 801 | try: |
| 802 | current = get_memory(process.pid) |
| 803 | except ProcessTerminatedError: |
| 804 | # It's possible the process terminated between .poll() |
| 805 | # and get_memory(). |
| 806 | break |
| 807 | memory.append(current) |
| 808 | stdout, stderr = process.communicate() |
| 809 | return stdout, stderr, memory |
| 810 | |
| 811 | |
| 812 | def _get_memory_with_ps(pid): |