How to properly stop phantomjs execution
As of July 2016, driver.close()
and driver.quit()
weren't sufficient for me. That killed the node
process but not the phantomjs
child process it spawned.
Following the discussion on this GitHub issue, the single solution that worked for me was to run:
import signaldriver.service.process.send_signal(signal.SIGTERM) # kill the specific phantomjs child procdriver.quit() # quit the node proc
Please note that this will obviously cause trouble if you have several threads/processes starting PhantomJS on your machine.
I've seen several people struggle with the same issue, but for me, the simplest workaround/hack was to execute the following from the command line through Python AFTER you have invoked driver.close()
or driver.quit()
:
pgrep phantomjs | xargs kill
The .close()
method is not guaranteed to release all resources associated with a driver instance. Note that these resources include, but may not be limited to, the driver executable (PhantomJS, in this case). The .quit()
method is designed to free all resources of a driver, including exiting the executable process.