Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9205487
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T23:57:39+00:00 2026-06-17T23:57:39+00:00

In summary, my problem is how do you easily make a connection resource a

  • 0

In summary, my problem is how do you easily make a connection resource a global variable? To be specific, I’d like to open a Redis queue connection and would like to use that in multiple functions without the hassle of passing it as a parameter, i.e.’

#===============================================================================
# Global variables
#===============================================================================
REDIS_QUEUE <- how to initialize

Then, in my main function, have

# Open redis queue connection to server
REDIS_QUEUE = redis.StrictRedis(host=SERVER_IP, port=6379, db=0)

And then use REDIS_QUEUE in multiple functions, e.g.

def sendStatusMsgToServer(statusMsg):
    print "\nSending status message to server:"
    print simplejson.dumps(statusMsg)
    REDIS_QUEUE.rpush(TLA_DATA_CHANNEL, simplejson.dumps(statusMsg))

I thought REDIS_QUEUE = none would work but it gives me

AttributeError: 'NoneType' object has no attribute 'rpush'

I’m new to Python, what’s the best way to solve this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T23:57:41+00:00Added an answer on June 17, 2026 at 11:57 pm

    If you want to set the value of a global variable from inside a function, you need to use the global statement. So in your main function:

    def main():
        global REDIS_QUEUE
        REDIS_QUEUE = redis.StrictRedis(host=SERVER_IP, port=6379, db=0)
        # whatever else
    

    Note that there’s no need to “initialize” the variable outside main before doing this, although you may want to just to document that the variable exists.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Post-Answer-Acceptance Summary: The problem was the use of a pointer to a stack variable
Summary of problem: I would like to create a master page, and from that
Problem Summary When run in batch mode, my user identity is lost but (like
You can't use wildcards in menu paths? A quick summary of my problem (which
The problem is easily pictured with an example here . The code goes like
Problem summary: I use OpenGL glReadPixels to get a screenshot but the buffer is
The problem is displaying summary band incorrectly . To make it more clear, I
Problem summary: (i) Widget in static portion of form works fine; but (ii) In
Summary of the problem: For some decimal values, when we convert the type from
Quick summary of my problem: first rendering of the view contains the elements in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.