websocketを使用しながらマルチプロセスでサブプロセスを動作させておきメモリ空間を共有させたいと思っているのですが、サブプロセスのルーチンが早々に停止してしまいます。
マルチプロセスだけなら走るのですがwebsocketを組み合わせるとうまく動かず困っています。
エラーメッセージ
該当のソースコード
python
1# websocket 2class WebsocketAPI(object): 3 def __init__(): 4 5 def run(): 6 7 def on_message(): 8 9 def on_close(): 10 11 def on_open(): 12 13# サブプロセス 14def test_func(d): 15 print("in test_func started") 16 d[1] = 200 17 print(d[1]) 18 d["test"] = "test1" 19 print(d["test"]) 20 while True: 21 print(d) 22 sleep(0.5) 23 24 25if __name__ == '__main__': 26 27 while True: 28 try: 29 with Manager() as manager: 30 d = manager.dict() 31 test_process = Process(target=test_func, args=(d)) 32 print("start") 33 test_process.start() 34 print("finished") 35 break 36 except ccxt.BaseError as e: 37 print(" error in SubProcess : test_func()",e) 38 print("recall") 39 sleep(1) 40 41 #API endpoint 42 url, channel, json_rpc = make_connection() 43 #ctrl + cで終了 44 while True: 45 try: 46 json_rpc.run() 47 break 48 except ccxt.BaseError as e: 49 print(" error in _MAIN_ json_rpc.run()", e) 50 url, channel, json_rpc = make_connection() 51
発生している問題・エラーメッセージ
(base) C:\test>python websocket.py start finished called _init_ websocket.WebSocketApp open 正常終了 json_rpc : <__main__.RealtimeAPI object at 0x0000023E460B6D68> --- request header --- ----------------------- --- response header --- ----------------------- called on_open connected streaming server send: b'\x81\xd1\x8b\xd1t\xbf\xf0\xf3\x19\xda\xff\xb9\x1b\xdb\xa9\xebT\x9d\xf8\xa4\x16\xcc\xe8\xa3\x1d\xdd\xee\xf3X\x9f\xa9\xa1\x15\xcd\xea\xbc\x07\x9d\xb1\xf1\x0f\x9d\xe8\xb9\x15\xd1\xe5\xb4\x18\x9d\xb1\xf1V\xd3\xe2\xb6\x1c\xcb\xe5\xb8\x1a\xd8\xd4\xb4\x0c\xda\xe8\xa4\x00\xd6\xe4\xbf\x07\xe0\xcd\x89+\xfd\xdf\x92+\xf5\xdb\x88V\xc2\xf6' ~~~~~~~~~~~~ ~~ websocket 処理~~ ~~~~~~~~~~~~ ~~~~~~~~~~~サブプロセスエラー~~~~~~~~~~~~~~~~ Process Process-2: Traceback (most recent call last): File "C:\Anaconda3_2\lib\multiprocessing\process.py", line 297, in _bootstrap self.run() File "C:\Anaconda3_2\lib\multiprocessing\process.py", line 99, in run self._target(*self._args, **self._kwargs) TypeError: test_func() missing 1 required positional argument: 'd' ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~ ~~ websocket 処理~~ ~~~~~~~~~~~~
サブプロセスについては最初のプリント文すら表示されません。
何が原因かわかれば教えてください。よろしくお願いします。
追記
初期エラーが改善され、次のエラーが生じたため編集コードとエラーを抜粋して追記します。 またサブプロセス1行目のプリント文までは出力されるようになりました。 引き続きよろしくお願いします。
発生している問題・エラーメッセージ2
~~~~~~~~~~~サブプロセスエラー~~~~~~~~~~~~~~~~ in test_func started Process Process-2: Traceback (most recent call last): File "C:\Anaconda3_2\lib\multiprocessing\managers.py", line 788, in _callmethod conn = self._tls.connection AttributeError: 'ForkAwareLocal' object has no attribute 'connection' During handling of the above exception, another exception occurred: Traceback (most recent call last): File "C:\Anaconda3_2\lib\multiprocessing\process.py", line 297, in _bootstrap self.run() File "C:\Anaconda3_2\lib\multiprocessing\process.py", line 99, in run self._target(*self._args, **self._kwargs) File "C:\test\websocket.py", line 563, in test_func d[1] = 200 File "<string>", line 2, in __setitem__ File "C:\Anaconda3_2\lib\multiprocessing\managers.py", line 792, in _callmethod self._connect() File "C:\Anaconda3_2\lib\multiprocessing\managers.py", line 779, in _connect conn = self._Client(self._token.address, authkey=self._authkey) File "C:\Anaconda3_2\lib\multiprocessing\connection.py", line 490, in Client c = PipeClient(address) File "C:\Anaconda3_2\lib\multiprocessing\connection.py", line 691, in PipeClient _winapi.WaitNamedPipe(address, 1000) FileNotFoundError: [WinError 2] 指定されたファイルが見つかりません。 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
該当のソースコード
python
1# サブプロセス 2# 変数を2つに修正 3def test_func(d,l): 4 print("in test_func") 5 d[1] = 200 6 print(d[1]) 7 d["test"] = "test1" 8 print(d["test"]) 9 while True: 10 print(d) 11 print(l) 12 sleep(0.5) 13 14if __name__ == '__main__': 15 16 while True: 17 try: 18 with Manager() as manager: 19 d = manager.dict() 20 ### 変数 l を追加 ### 21 l = manager.list(range(5)) 22 test_process = Process(target=test_func, args=(d,l)) 23 print("start") 24 test_process.start() 25 print("finished") 26 break 27 except ccxt.BaseError as e: 28 print(" error in SubProcess : test_func()",e) 29 print("recall") 30 sleep(1) 31 32 #API endpoint 33 url, channel, json_rpc = make_connection() 34 #ctrl + cで終了 35 while True: 36 try: 37 json_rpc.run() 38 break 39 except ccxt.BaseError as e: 40 print(" error in _MAIN_ json_rpc.run()", e) 41 url, channel, json_rpc = make_connection() 42
追記2
※抜けていたプログラムコードを追記します。
該当のソースコード2
python
1# API 接続 2def make_connection(): 3 #API endpoint 4 url = 'URL' 5 channel = '希望するAPI情報の種類(str)' 6 json_rpc = WebsocketAPI(url=url, channel=channel) 7 print("json_rpc : ", json_rpc) 8 return url, channel, json_rpc 9
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2019/05/12 11:33
2019/05/12 11:33
2019/05/12 11:35
2019/05/12 11:46
2019/05/12 11:52
2019/05/12 12:18
2019/05/12 12:20
2019/05/12 12:22
2019/05/12 12:28
2019/05/12 12:29
2019/05/12 12:30
2019/05/12 12:31
2019/05/12 12:32
2019/05/12 12:34
2019/05/12 12:36
2019/05/12 12:37
2019/05/12 12:40
2019/05/12 12:40
2019/05/12 12:49
2019/05/12 12:51
2019/05/12 12:51
2019/05/12 12:53 編集
2019/05/12 12:55
2019/05/12 12:57
2019/05/12 12:59
2019/05/12 13:03 編集
2019/05/12 13:12