elbakramer / koapy

KOAPY 는 키움 OpenAPI 를 Python 에서 쉽게 사용할 수 있도록 만든 라이브러리 패키지 및 툴입니다.

Home Page:https://koapy.readthedocs.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

32bit server, 64bit client 실행 중 오류

AimHighDS opened this issue · comments

Describe the bug
먼저 훌륭한 소스를 공개해주셔서 감사합니다. koapy 32bit server를 실행하고, 64bit에서 login(성공) 후 stockinfo 호출 시 오류 발생

To Reproduce
Steps to reproduce the behavior:

  1. python3.9 32bit > koapy serv 실행
(koapy-srv-py3.9) D:\pjt_py\koapy_srv>koapy serve
2022-10-15 01:19:39,454 [DEBUG] Creating manager application - KiwoomOpenApiPlusManagerApplication.py:206
2022-10-15 01:19:42,001 [DEBUG] Creating server application - KiwoomOpenApiPlusServerApplication.py:150
2022-10-15 01:19:42,290 [DEBUG] Started server application - KiwoomOpenApiPlusServerApplication.py:394
2022-10-15 01:19:42,398 [DEBUG] Started manager application - KiwoomOpenApiPlusManagerApplication.py:664
  1. python3.10 64bit > koapy login
[GetPCIdentity] VER 3.2.0.0  build 2015.8.12

[GetPCIdentity] VER 3.2.0.0  build 2015.8.12
2022-10-15 01:20:56,661 [DEBUG] OnEventConnect(0) - KiwoomOpenApiPlusLoggingEventHandler.py:89
  1. python3.10 64bit > koapy get stockinfo -c 005930
    오류 발생

Screenshots

(koapy-cli-py3.10) D:\pjt_py\koapy_cli>koapy get stockinfo -c 005930
Traceback (most recent call last):
  File "runpy.py", line 196, in _run_module_as_main
  File "runpy.py", line 86, in _run_code
  File "D:\pjt_py\koapy_cli\.venv\Scripts\koapy.exe\__main__.py", line 7, in <module>
  File "D:\pjt_py\koapy_cli\.venv\lib\site-packages\koapy\cli\__init__.py", line 391, in main
    cli()
  File "D:\pjt_py\koapy_cli\.venv\lib\site-packages\click\core.py", line 1130, in __call__
    return self.main(*args, **kwargs)
  File "D:\pjt_py\koapy_cli\.venv\lib\site-packages\click\core.py", line 1055, in main
    rv = self.invoke(ctx)
  File "D:\pjt_py\koapy_cli\.venv\lib\site-packages\click\core.py", line 1657, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "D:\pjt_py\koapy_cli\.venv\lib\site-packages\click\core.py", line 1657, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "D:\pjt_py\koapy_cli\.venv\lib\site-packages\click\core.py", line 1404, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "D:\pjt_py\koapy_cli\.venv\lib\site-packages\click\core.py", line 760, in invoke
    return __callback(*args, **kwargs)
  File "D:\pjt_py\koapy_cli\.venv\lib\site-packages\click\decorators.py", line 26, in new_func
    return f(get_current_context(), *args, **kwargs)
  File "D:\pjt_py\koapy_cli\.venv\lib\site-packages\koapy\cli\extensions\verbose_option.py", line 128, in new_func
    return ctx.invoke(f, *args, **kwargs)
  File "D:\pjt_py\koapy_cli\.venv\lib\site-packages\click\core.py", line 760, in invoke
    return __callback(*args, **kwargs)
  File "D:\pjt_py\koapy_cli\.venv\lib\site-packages\koapy\cli\commands\get\stock_meta\stockname.py", line 24, in stockname
    with KiwoomOpenApiPlusEntrypoint(port=port) as context:
  File "D:\pjt_py\koapy_cli\.venv\lib\site-packages\koapy\backend\kiwoom_open_api_plus\core\KiwoomOpenApiPlusEntrypoint.py", line 31, in __init__
    self._server_executable = get_32bit_executable()
  File "D:\pjt_py\koapy_cli\.venv\lib\site-packages\koapy\config.py", line 303, in get_32bit_executable
    return get_executable_from_executable_config(executable_config)
  File "D:\pjt_py\koapy_cli\.venv\lib\site-packages\koapy\config.py", line 289, in get_executable_from_executable_config
    return get_executable_from_conda_envname(envname)
  File "D:\pjt_py\koapy_cli\.venv\lib\site-packages\koapy\config.py", line 248, in get_executable_from_conda_envname
    return subprocess.check_output(
  File "subprocess.py", line 421, in check_output
  File "subprocess.py", line 503, in run
  File "subprocess.py", line 971, in __init__
  File "subprocess.py", line 1440, in _execute_child
FileNotFoundError: [WinError 2] 지정된 파일을 찾을 수 없습니다
Exception ignored in: <function KiwoomOpenApiPlusEntrypoint.__del__ at 0x0000019BC1A21F30>
Traceback (most recent call last):
  File "D:\pjt_py\koapy_cli\.venv\lib\site-packages\koapy\backend\kiwoom_open_api_plus\core\KiwoomOpenApiPlusEntrypoint.py", line 62, in __del__
    self.close()
  File "D:\pjt_py\koapy_cli\.venv\lib\site-packages\koapy\backend\kiwoom_open_api_plus\core\KiwoomOpenApiPlusEntrypoint.py", line 89, in close
    self.close_client()
  File "D:\pjt_py\koapy_cli\.venv\lib\site-packages\koapy\backend\kiwoom_open_api_plus\core\KiwoomOpenApiPlusEntrypoint.py", line 80, in close_client
    self._client.close()
  File "D:\pjt_py\koapy_cli\.venv\lib\site-packages\koapy\backend\kiwoom_open_api_plus\core\KiwoomOpenApiPlusEntrypoint.py", line 96, in __getattr__
    return self.__getattribute__(name)
AttributeError: 'KiwoomOpenApiPlusEntrypoint' object has no attribute '_client'

Environment (please complete the following information):

  • OS: [Windows 10]
  • Python Version: [Python 3.9 32Bit / Python 3.10 64Bit]
  • KOAPY Version: [0.9.0]

그래서, 원인을 찾던 중 koapy\backend\kiwoom_open_api_plus\core\KiwoomOpenApiPlusEntrypoint.py 파일 내용을 일부 수정 후 테스트 결과 정상적으로 동작을 했습니다.
소스를 수정하는 것 외에 다른 방법이 있는 지 궁금하네요.

import threading

from koapy.backend.kiwoom_open_api_plus.core.KiwoomOpenApiPlusEntrypointMixin import (
    KiwoomOpenApiPlusEntrypointMixin,
)
from koapy.backend.kiwoom_open_api_plus.grpc.KiwoomOpenApiPlusServiceClient import (
    KiwoomOpenApiPlusServiceClient,
)
**from koapy.config import config, get_32bit_executable, get_64bit_executable**# 추가
from koapy.utils.logging import get_verbosity
from koapy.utils.logging.Logging import Logging
from koapy.utils.networking import get_free_localhost_port
from koapy.utils.subprocess import Popen`


class KiwoomOpenApiPlusEntrypoint(KiwoomOpenApiPlusEntrypointMixin, Logging):
    def __init__(
        self,
        port=None,
        client_check_timeout=None,
    ):
        if port is None:
            port = (
                config.get("koapy.backend.kiwoom_open_api_plus.grpc.port", 0)
                or get_free_localhost_port()
            )

        self._port = port
        self._client_check_timeout = client_check_timeout

        **#self._server_executable = get_32bit_executable() # comment out
        self._server_executable = get_64bit_executable()**  # 추가

안녕하세요. 버그 공유 감사합니다.

고치신 부분처럼 KiwoomOpenApiPlusEntrypoint 내에서 32bit python 을 확인하는 부분이 문제가 되어 보입니다.

이게 제 기준으로 conda 기반으로 각 64bit/32bit python 이 설치된 환경을 사용하고 있는데요.
해당 환경을 기준으로 작성하는 과정에서 이외의 환경, conda 를 사용하지 않고 설치된 환경을 고려하지 않아서 발생한 문제로 보이네요.

구체적으로, 따로 돌고 있는 서버 없이 바로 KiwoomOpenApiPlusEntrypoint 객체를 생성해서 사용하는 식의 시나리오에서는
내부 자식 프로세스를 통해 자체적으로 서버 프로세스를 띄운 후에 거기에 클라이언트가 연결하도록 되어있습니다.

해당 과정에서 자식 서버 프로세스를 위한 32bit python 경로가 필요한 건데요.
공유 주신 사용 환경에서는 별도로 서버를 띄우고 있으시기 때문에 해당 과정이 딱히 필요 없긴 합니다.

6140934 커밋을 통해 conda 명령이 존재하지 않는 경우에 대한 예외 처리를 추가해보았는데요.
다음 버전 업데이트 이전까지는 요정도로만 수정해서 사용하셔도 될 것 같구요.

아니면 이게 기본으로 주어지는 설정파일에서 conda 로 설치된 32bit python 을 가정해서 설정되어 있는거라..
설정파일에서 아래와 비슷하게 직접적으로 32bit python 의 경로를 지정해줄 수도 있을 것 같습니다.

64bit = { path = "python" }