Skip to content
This repository has been archived by the owner on Nov 29, 2018. It is now read-only.

python: memory and file descriptor leak with PhantomJS #7304

Closed
lukeis opened this issue Mar 4, 2016 · 7 comments
Closed

python: memory and file descriptor leak with PhantomJS #7304

lukeis opened this issue Mar 4, 2016 · 7 comments

Comments

@lukeis
Copy link
Member

lukeis commented Mar 4, 2016

Originally reported on Google Code with ID 7304


What steps will reproduce the problem?
1. Do the following in python 2.7.6

from selenium import webdriver
import gc
while True:
  d=webdriver.PhantomJS('phantomjs')
  d.quit()
  d=None
  gc.collect()

2. ls /proc/[Python process id]/fd
0  10  12  14  16  18  2   21  23  25  27  29  30  32  34  36  38  40  42  44  46 
48  5   51  53  6  8
1  11  13  15  17  19  20  22  24  26  28  3   31  33  35  37  39  41  43  45  47 
49  50  52  54  7  9

3. There're a lot of leaking file descriptors!

What is the expected output? What do you see instead?

There should not be any file descriptor leak.

Selenium version: 2.41.0 (installed using "pip install")
OS: Ubuntu Desktop 14.04 LTS on x86_64
Browser: PhantomJS
Browser version: 1.9.0 (from ubuntu repository)
Python Version: 2.7.6

Please provide any additional information below. A sample reduced test
case, or a public URL that demonstrates the problem will intrigue our merry
band of Open Source developers far more than nothing at all: they'll be far
more likely to look at your problem if you make it easy for them!


Reported by kcm1700 on 2014-05-05 14:27:14

@lukeis
Copy link
Member Author

lukeis commented Mar 4, 2016

I have found that this issue is not in this Selenium version: 2.40.0 (and 2.30.0, 2.35.0,
etc)

Reported by kcm1700 on 2014-05-06 17:28:34

@lukeis
Copy link
Member Author

lukeis commented Mar 4, 2016

I see one broken pipe left in version 2.40.0. But there was no broken pipe at all in
version 2.30.0. Is this relevant change?

Reported by kcm1700 on 2014-05-06 17:37:36

@lukeis
Copy link
Member Author

lukeis commented Mar 4, 2016

After doing some git bisect, I found that the issue is introduced in "[8fc478b09ea3c76800d09ab6681f9c3895b1bbc4]
python switch_to_ deprecation / adding switch_to class like the other language bindings"

Reported by kcm1700 on 2014-05-06 17:55:53

@lukeis
Copy link
Member Author

lukeis commented Mar 4, 2016

Ok, the situation is similar to this one.
http://ideone.com/u2rD92

A -> switch_to
B -> webdriver (in phantomjs module. it defined __del__)
C -> Popen object (it has __del__ by default)

Reported by kcm1700 on 2014-05-06 18:35:53

@lukeis
Copy link
Member Author

lukeis commented Mar 4, 2016

This issue was closed by revision f6e1797dde53.

Reported by luke.semerau on 2014-05-07 04:25:16

  • Status changed: Fixed

@lukeis
Copy link
Member Author

lukeis commented Mar 4, 2016

There is a problem with calling "stop()" from Service's "__del__()" method. From time
to time, we are getting:

 > Exception AttributeError: "'Service' object has no attribute 'process'" in <bound
method Service.__del__ of <selenium.webdriver.phantomjs.service.Service object at 0x7fbb28dc17d0>>
ignored

this happens in the "stop()" method where the service instance is not available anymore
(is None).

See more at relevant stackoverflow post: http://stackoverflow.com/questions/27674088/scrapy-with-selenium-webdriver-failing-to-instantiate.

Reported by AfanasieffAV on 2014-12-28 06:45:12

@lukeis
Copy link
Member Author

lukeis commented Mar 4, 2016

Reported by luke.semerau on 2015-09-17 18:22:23

  • Labels added: Restrict-AddIssueComment-Commit

@lukeis lukeis closed this as completed Mar 4, 2016
@SeleniumHQ SeleniumHQ locked and limited conversation to collaborators Mar 4, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

1 participant