arseniycodes / arseniycodes/socrates
Subprocess is not cleaned up
- Dominant language
- Python
- Stars
- 70
- Forks
- 4
- PR merge metrics
- No merged PRs in 30d
Description
Hello! Cool project, thank you.
After running the tests
```
python3.7 socrates.py -p 1 /philosophers
```
Grep'ing processes with the name `philo`
```
ps aux | head -n +1
ps aux | grep "philo"
```
Outputs:
```
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
user42 7265 0.4 0.0 47680 856 pts/1 Sl 20:32 0:00 /philosophers/philo_one/philo_one 4 311 150 150
user42 7273 0.4 0.0 47680 876 pts/1 Sl 20:32 0:00 /philosophers/philo_one/philo_one 4 311 150 150
user42 7280 0.4 0.0 47680 888 pts/1 Sl 20:32 0:00 /philosophers/philo_one/philo_one 4 311 150 150
user42 7288 0.4 0.0 55876 948 pts/1 Sl 20:33 0:00 /philosophers/philo_one/philo_one 5 600 150 150
user42 7297 0.4 0.0 55876 876 pts/1 Sl 20:33 0:00 /philosophers/philo_one/philo_one 5 600 150 150
user42 7305 0.4 0.0 55876 836 pts/1 Sl 20:33 0:00 /philosophers/philo_one/philo_one 5 600 150 150
user42 7386 0.0 0.0 16952 1060 pts/1 S+ 20:33 0:00 grep --color=auto --exclude-dir=.bzr --exclude-dir=CVS --exclude-dir=.git --exclude-dir=.hg --exclude-dir=.svn --exclude-dir=.idea --exclude-dir=.tox philo_one
```
I think this is happening because the program is running in a shell and process.kill() seems to kill only the shell.
A posible fix is to [import shlex](https://docs.python.org/3/library/shlex.html) and in `assert_runs_for_at_least()` set shell to False
```
process = subprocess.Popen(shlex.split(command), stdout=subprocess.DEVNULL, shell=False)
```
This will work for philo_one and philo_two because they use threads.
philo_three it's creating multiple subprocesses, so they need to be cleaned up before returning.
Tested on `Xubuntu 18.04` with `python3.7`
Edit:
Just saw the function `processes_still_running()` which should clean the processes and I don't know why it's not working on my machine, will test it more since I'm currently working on philosophers project.
Contributor guide
No contributing guide indexed for this repository
Research direction
Start with assert_runs_for_at_least() in socrates.py and inspect how processes_still_running() handles the subprocesses launched by the philosophers tests. Reproduce the command shown with Python 3.7, including philo_three, and verify that no philosopher processes remain after the tests finish.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- testing-qa
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100