I also have a python script running on my mac using selenium to do some stuff using PhantomJS as the webdriver.
When my test is running, there are three processes to note are here:
$ ps -ef | grep [p]hantomjs 501 28085 24925 0 9:03pm ttys002 0:00.34 python test.py 501 28088 28085 0 9:03pm ttys002 0:00.14 node /usr/local/bin/phantomjs --cookies-file=/var/folders/nq/hjz03w6d4fs620197d_zwg0m0000gn/T/tmp8xLNaH --webdriver=55075 501 28090 28088 0 9:03pm ttys002 0:00.71 /usr/local/lib/node_modules/phantomjs/lib/phantom/bin/phantomjs --cookies-file=/var/folders/nq/hjz03w6d4fs620197d_zwg0m0000gn/T/tmp8xLNaH --webdriver=55075
Note the second column which are the process numbers, and the third which are that processes parent.
My test script is the parent. There is a node process which has my test script as a parent, then there is another PhantomJS process whose parent is the node process. Don’t ask me why there’s two PhantomJS processes, I guess it is just how it’s designed to work?
Anyway, in my mac’s activity monitor, I can see this:
Note the PID number 28090.
After my test finishes running this, processes hangs around, just like you too. If I check for still running processes I can see:
$ ps -ef | grep [p]hantomjs 501 28090 1 0 9:03pm ttys002 0:18.93 /usr/local/lib/node_modules/phantomjs/lib/phantom/bin/phantomjs --cookies-file=/var/folders/nq/hjz03w6d4fs620197d_zwg0m0000gn/T/tmp8xLNaH --webdriver=55075
So it appears to me that
driver.quit() exits the node process, the one with PID number 28088, but it leaves its child orphaned. I don’t know if this is intentional. If it’s not intentional, then I think there isn’t a ‘proper’ way to exit this process in your code.
Therefore I would use your language’s equivalent of
kill -9 28090, just after