question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

inbox.stream not returning None properly and instead heading into an unbreakable loop

See original GitHub issue

Describe the Bug

When running a inbox.stream(pause_after=-1) I’d expect it to:

  1. Fetch previous unread.
    1. Return None after is done.
    1. When next polled, if no data is received, should return None, but it does not, it instead starts decreasing limit from 100 to 75, then jumps to 100 and repeats the cycle

Desired Result

Desired result: For it to return None, rather than going down to 99, 98 etc

Relevant Logs

The very first request it does are like the below, but it uses before="t4_ANID", unfortunately it scrolls off my screen too quick for me to grab it.

DEBUG:prawcore:Response: 200 (8580 bytes)
DEBUG:prawcore:Fetching: GET https://oauth.reddit.com/message/unread/
DEBUG:prawcore:Data: None
DEBUG:prawcore:Params: {'before': None, 'mark': False, 'limit': 96, 'raw_json': 1}
DEBUG:urllib3.connectionpool:https://oauth.reddit.com:443 "GET /message/unread/?mark=False&limit=96&raw_json=1 HTTP/1.1"
 200 8580
DEBUG:prawcore:Response: 200 (8580 bytes)
DEBUG:prawcore:Fetching: GET https://oauth.reddit.com/message/unread/
DEBUG:prawcore:Data: None
DEBUG:prawcore:Params: {'before': None, 'mark': False, 'limit': 95, 'raw_json': 1}
DEBUG:urllib3.connectionpool:https://oauth.reddit.com:443 "GET /message/unread/?mark=False&limit=95&raw_json=1 HTTP/1.1"
 200 8580
DEBUG:prawcore:Response: 200 (8580 bytes)
DEBUG:prawcore:Fetching: GET https://oauth.reddit.com/message/unread/
DEBUG:prawcore:Data: None
DEBUG:prawcore:Params: {'before': None, 'mark': False, 'limit': 94, 'raw_json': 1}
DEBUG:urllib3.connectionpool:https://oauth.reddit.com:443 "GET /message/unread/?mark=False&limit=94&raw_json=1 HTTP/1.1"
 200 8580
DEBUG:prawcore:Response: 200 (8580 bytes)
DEBUG:prawcore:Fetching: GET https://oauth.reddit.com/message/unread/
DEBUG:prawcore:Data: None
DEBUG:prawcore:Params: {'before': None, 'mark': False, 'limit': 93, 'raw_json': 1}
DEBUG:urllib3.connectionpool:https://oauth.reddit.com:443 "GET /message/unread/?mark=False&limit=93&raw_json=1 HTTP/1.1"
 200 8580
DEBUG:prawcore:Response: 200 (8580 bytes)
DEBUG:prawcore:Fetching: GET https://oauth.reddit.com/message/unread/
DEBUG:prawcore:Data: None
DEBUG:prawcore:Params: {'before': None, 'mark': False, 'limit': 92, 'raw_json': 1}

Code to reproduce the bug

def run_inbox(ist=0):
    if(ist==0):
     ist=g.reddit.inbox.stream(pause_after=-1)
    for y in ist:
     if(y==None):
      break
     # do stuff
    return ist

My code example does not include the Reddit() initialization to prevent credential leakage.

Yes

This code has previously worked as intended.

Yes

Operating System/Environment

Running on windows 10.

Python Version

3.8

PRAW Version

latest on pip

Prawcore Version

latest on pip

Anything else?

No response

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
NathanTech7713commented, Apr 29, 2022

The problem is probably the creation of the stream inside the function, this only works well if the same stream object is reused.

Yep this fixed it. Sorry for the bother.

0reactions
LilSpazJoekpcommented, Apr 29, 2022

The problem is probably the creation of the stream inside the function, this only works well if the same stream object is reused.

What’s the logic behind starting at 100, dropping to 75, and then looping back to 100 just out of interest? What causes that to happen?

Incrementing of the limit parameter is to help break caches.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Python return "None" prevents following for loop
I'm using Tweepy to stream tweets.
Read more >
Function keeps returning None - Codecademy
Hello, My function keeps returning None instead of True or False. It seems it doesn't go in the for loop, but I don't...
Read more >
Rob Landley's Blog Thing for 2022
I had a "git log" blocked on "less" in there, but the PROCESS that's running says it's git pack on the command line....
Read more >
Every Lana Del Rey Song, Ranked: Critic's List - Billboard
Ranking all 113 of Lana Del Rey's individual songs allows a valuable opportunity to take a critical look at her entire body of...
Read more >
- CONFIRMATION HEARING ON THE NOMINATION OF HON ...
BRETT M. KAVANAUGH TO BE AN ASSOCIATE JUSTICE OF THE SUPREME COURT OF THE ... 2921 Arnold, Carrie, ``Life After Rape: The Sexual...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found