filamoon / pyapollo

Python client for Ctrip's Apollo.
Apache License 2.0
194 stars 94 forks source link

eventlet 如何使用,求demo #2

Open caimaoy opened 6 years ago

caimaoy commented 6 years ago

eventlet 如何使用?

filamoon commented 6 years ago

比如用gunicorn启动flask,如果并发模式采用 eventlet,就可以用 eventlet 的long poll

caimaoy commented 6 years ago

我还在想如果我用 flask worker 的模式 会有很多线程的问题。

filamoon commented 6 years ago

我在 celery 的 eventlet 模式下,实证可用,没有 thread 模式下必须等待30s才能退出的问题

sunguangran commented 6 years ago

eventlet 异步无效,请问是什么问题,环境mac py2.7

filamoon commented 6 years ago

需要先 monkey patch。如果用的 gunicorn 或者 celery -P eventlet,它们自己会负责初始化,就什么都不用做。

xdjiangyang commented 6 years ago

@filamoon 直接利用pyapollo编写代码时 eventlet 异步确实无效,在 apollo_client.py 的 import eventlet 下面添加 eventlet.monkey_patch() 就可以让 eventlet 异步生效。可否修改一下源码?

filamoon commented 6 years ago

def start(self, use_eventlet=False, eventlet_monkey_patch=False) 增加了一个开关来控制是否调用 eventlet.monkey_patch()

sunguangran commented 6 years ago

还行不会执行啊,只有调用t.wait() 方法才会触发执行,但wait会阻塞~

sunguangran commented 6 years ago

大家有执行成功的?

luciferYu commented 6 years ago

我想在django中使用apollo配置中心来实现一些限速策略的设置。 于是我在settings.py中加入了

client = ApolloClient(app_id='WSCenter', cluster='default', config_server_url='http://192.168.14.35:8080',timeout=61)
client.start()
SECRET_KEY = client.get_value('SECRET_KEY', 'l^h%b2l9i6o-+g$ottqyw=+czg8me$=*aegww&6l)f3y&qlbg#')
'DEFAULT_THROTTLE_RATES': {
        'anon': '100/day',
        'user': client.get_value('throttle_rates_user', '100/minute'),  # 测试用
    },

重启django是可以读到配置文件的,但实现不了在线更新, 然后我修改start代码传参 client.start(use_eventlet=True,eventlet_monkey_patch=True) 报如下错误:

 File "E:\WSC\WSC\settings.py", line 22, in <module>
    client.start(use_eventlet=True,eventlet_monkey_patch=True)
  File "E:\venv\WSC-x03IkHfZ\lib\site-packages\pyapollo\apollo_client.py", line 67, in start
    eventlet.monkey_patch()
  File "E:\venv\WSC-x03IkHfZ\lib\site-packages\eventlet\patcher.py", line 265, in monkey_patch
    _green_existing_locks()
  File "E:\venv\WSC-x03IkHfZ\lib\site-packages\eventlet\patcher.py", line 356, in _green_existing_locks
    if isinstance(obj, rlock_type):
  File "E:\venv\WSC-x03IkHfZ\lib\site-packages\django\utils\functional.py", line 215, in inner
    self._setup()
  File "E:\venv\WSC-x03IkHfZ\lib\site-packages\django\conf\__init__.py", line 43, in _setup
    self._wrapped = Settings(settings_module)
  File "E:\venv\WSC-x03IkHfZ\lib\site-packages\django\conf\__init__.py", line 125, in __init__
    raise ImproperlyConfigured("The SECRET_KEY setting must not be empty.")
django.core.exceptions.ImproperlyConfigured: The SECRET_KEY setting must not be empty.

Process finished with exit code 1

请问可能是哪里发生了问题?