前提・実現したいこと
入門Python3(オライリー・ジャパン)のp344において、1つ目のプログラムをバックグラウンドで起動した後に2つ目のプログラムを起動したいです。
正しく起動すると以下のように表示されます。
Python3
1[2] 81691 2Dryer is starting
1つ目のプログラムredis_washer.pyは以下のファイルです。
Python3
1import redis 2conn = redis.Redis() 3print('Dryer is starting') 4while True: 5 msg = conn.blpop('dishes') 6 if not msg: 7 break 8 val = msg[1].decode('utf-8') 9 if val == 'quit': 10 break 11 print('Dried', val) 12print('Dishes are dried')
発生している問題・エラーメッセージ
以下のように接続のエラーなどが発生します。
該当のソースコード
Python3
1kotaMBA:python kota$ python redis_dryer.py & 2[1] 12722 3kotaMBA:python kota$ Dryer is starting 4Traceback (most recent call last): 5 File "/Users/kota/.pyenv/versions/3.6.5/lib/python3.6/site-packages/redis/connection.py", line 484, in connect 6 sock = self._connect() 7 File "/Users/kota/.pyenv/versions/3.6.5/lib/python3.6/site-packages/redis/connection.py", line 541, in _connect 8 raise err 9 File "/Users/kota/.pyenv/versions/3.6.5/lib/python3.6/site-packages/redis/connection.py", line 529, in _connect 10 sock.connect(socket_address) 11ConnectionRefusedError: [Errno 61] Connection refused 12 13During handling of the above exception, another exception occurred: 14 15Traceback (most recent call last): 16 File "/Users/kota/.pyenv/versions/3.6.5/lib/python3.6/site-packages/redis/client.py", line 667, in execute_command 17 connection.send_command(*args) 18 File "/Users/kota/.pyenv/versions/3.6.5/lib/python3.6/site-packages/redis/connection.py", line 610, in send_command 19 self.send_packed_command(self.pack_command(*args)) 20 File "/Users/kota/.pyenv/versions/3.6.5/lib/python3.6/site-packages/redis/connection.py", line 585, in send_packed_command 21 self.connect() 22 File "/Users/kota/.pyenv/versions/3.6.5/lib/python3.6/site-packages/redis/connection.py", line 489, in connect 23 raise ConnectionError(self._error_message(e)) 24redis.exceptions.ConnectionError: Error 61 connecting to localhost:6379. Connection refused. 25 26During handling of the above exception, another exception occurred: 27 28Traceback (most recent call last): 29 File "/Users/kota/.pyenv/versions/3.6.5/lib/python3.6/site-packages/redis/connection.py", line 484, in connect 30 sock = self._connect() 31 File "/Users/kota/.pyenv/versions/3.6.5/lib/python3.6/site-packages/redis/connection.py", line 541, in _connect 32 raise err 33 File "/Users/kota/.pyenv/versions/3.6.5/lib/python3.6/site-packages/redis/connection.py", line 529, in _connect 34 sock.connect(socket_address) 35ConnectionRefusedError: [Errno 61] Connection refused 36 37During handling of the above exception, another exception occurred: 38 39Traceback (most recent call last): 40 File "redis_dryer.py", line 5, in <module> 41 msg = conn.blpop('dishes') 42 File "/Users/kota/.pyenv/versions/3.6.5/lib/python3.6/site-packages/redis/client.py", line 1269, in blpop 43 return self.execute_command('BLPOP', *keys) 44 File "/Users/kota/.pyenv/versions/3.6.5/lib/python3.6/site-packages/redis/client.py", line 673, in execute_command 45 connection.send_command(*args) 46 File "/Users/kota/.pyenv/versions/3.6.5/lib/python3.6/site-packages/redis/connection.py", line 610, in send_command 47 self.send_packed_command(self.pack_command(*args)) 48 File "/Users/kota/.pyenv/versions/3.6.5/lib/python3.6/site-packages/redis/connection.py", line 585, in send_packed_command 49 self.connect() 50 File "/Users/kota/.pyenv/versions/3.6.5/lib/python3.6/site-packages/redis/connection.py", line 489, in connect 51 raise ConnectionError(self._error_message(e)) 52redis.exceptions.ConnectionError: Error 61 connecting to localhost:6379. Connection refused. 53
試したこと
ファイルの文法ミスのチェック
補足情報(FW/ツールのバージョンなど)
PCはMac、Pythonはver3.6.5を用いています。
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。