要約すると、私の問題は、接続リソースをグローバル変数に簡単に作成する方法です。具体的には、Redisキュー接続を開き、パラメーターとして渡す手間をかけずに、複数の関数で使用したいと思います。
#===============================================================================
# Global variables
#===============================================================================
REDIS_QUEUE <- how to initialize
次に、私の主な機能で、
# Open redis queue connection to server
REDIS_QUEUE = redis.StrictRedis(host=SERVER_IP, port=6379, db=0)
そしてREDIS_QUEUE
、複数の機能で使用します。
def sendStatusMsgToServer(statusMsg):
print "\nSending status message to server:"
print simplejson.dumps(statusMsg)
REDIS_QUEUE.rpush(TLA_DATA_CHANNEL, simplejson.dumps(statusMsg))
REDIS_QUEUE = none
私はうまくいくと思ったが、それは私に与える
AttributeError: 'NoneType' object has no attribute 'rpush'
私はPythonを初めて使用しますが、これを解決するための最良の方法は何ですか?