Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feedparser seems to occasionally hang and has no timeout #76

Open
peterashwell opened this issue Jul 10, 2016 · 3 comments

Comments

@peterashwell
Copy link

commented Jul 10, 2016

According to this the default timeout in urllib2 is -1, or None. So... this is a problem for long running programs, when occasionally some connection will hang everything.

Solution is pretty simple, add a timeout to the 'open' here

f = opener.open(request)

I'll fork and try make a fix

@rigid

This comment has been minimized.

Copy link

commented Feb 19, 2017

this issue seems like a real problem for there seems to be no clean workaround. Can't wait to see the next release because of that.

@darklow

This comment has been minimized.

Copy link

commented Jul 4, 2017

If you want a quick workaround you can monkey patch and use requests lib instead with proper timeout. It also fixes https certificate issues I had with default feedparser url open implementation. This is how I do it:

import requests
import feedparser

feedparser._open_resource = lambda *args, **kwargs: feedparser._StringIO(requests.get(args[0], timeout=15).content)
@hivemall

This comment has been minimized.

Copy link

commented Sep 11, 2019

have very simple app polling, once in a while feedparser does not return and needs 2x ^C to exit the script, and it then prints:

^CTraceback (most recent call last):
  File "frontend/myfeed/src/main.py", line 48, in main
  File "/home/user/.local/share/virtualenvs/workspace_python-Cp_/lib/python3.7/site-packages/feedparser.py", line 3841, in parse
    data = f.read()
  File "/home/user/.pyenv/versions/3.7.4/lib/python3.7/http/client.py", line 464, in read
    return self._readall_chunked()
  File "/home/user/.pyenv/versions/3.7.4/lib/python3.7/http/client.py", line 574, in _readall_chunked
    value.append(self._safe_read(chunk_left))
  File "/home/user/.pyenv/versions/3.7.4/lib/python3.7/http/client.py", line 620, in _safe_read
    chunk = self.fp.read(min(amt, MAXAMOUNT))
  File "/home/user/.pyenv/versions/3.7.4/lib/python3.7/socket.py", line 589, in readinto
    return self._sock.recv_into(b)
  File "/home/user/.pyenv/versions/3.7.4/lib/python3.7/ssl.py", line 1071, in recv_into
    return self.read(nbytes, buffer)
  File "/home/user/.pyenv/versions/3.7.4/lib/python3.7/ssl.py", line 929, in read
    return self._sslobj.read(len, buffer)
KeyboardInterrupt

^CTraceback (most recent call last):
  File "frontend/myfeed/src/main.py", line 56, in <module>
  File "frontend/myfeed/src/main.py", line 53, in main

Not sure if related and if above fixes this. I am using the latest pip install version

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants
You can’t perform that action at this time.