我最近在Openstack oslo_service模块中使用python,我试图在Openstack进程中设置信号(例如SIGUSR2
)以重新加载一些配置。
我插入一段代码来注册如下信号:
...
# the AgentService is inherited from oslo_service.service.Service
svc = AgentService(
host=mgr.agent_host,
topic=constants.TOPIC_LOADBALANCER_AGENT_V2,
manager=mgr
)
def handler(signum, frame):
# reload configurations
mgr.lbdriver.init_esd()
signal.signal(signal.SIGUSR2, handler)
# it will spawn greenthread of AgentService.
service.launch(cfg.CONF, svc).wait()
...
该服务可以成功启动,但是当我向进程ID发送SIGUSR2
时,服务日志显示此错误AssertionError: do not call blocking functions from the mainloop
。
错误的详细信息记录如下:
ERROR oslo_service.threadgroup [None req-a3117016-f380-4961-a8e5-6a346036bec2 None None] Error waiting on thread.: AssertionError: do not call blocking functions from the mainloop
ERROR oslo_service.threadgroup Traceback (most recent call last):
ERROR oslo_service.threadgroup File "/usr/lib/python2.7/site-packages/oslo_service/threadgroup.py", line 116, in _perform_action_on_threads
ERROR oslo_service.threadgroup action_func(x)
ERROR oslo_service.threadgroup File "/usr/lib/python2.7/site-packages/oslo_service/threadgroup.py", line 160, in <lambda>
ERROR oslo_service.threadgroup lambda x: x.wait(),
ERROR oslo_service.threadgroup File "/usr/lib/python2.7/site-packages/oslo_service/threadgroup.py", line 57, in wait
ERROR oslo_service.threadgroup return self.thread.wait()
ERROR oslo_service.threadgroup File "/usr/lib/python2.7/site-packages/eventlet/greenthread.py", line 175, in wait
ERROR oslo_service.threadgroup return self._exit_event.wait()
ERROR oslo_service.threadgroup File "/usr/lib/python2.7/site-packages/eventlet/event.py", line 121, in wait
ERROR oslo_service.threadgroup return hubs.get_hub().switch()
ERROR oslo_service.threadgroup File "/usr/lib/python2.7/site-packages/eventlet/hubs/hub.py", line 294, in switch
ERROR oslo_service.threadgroup return self.greenlet.switch()
ERROR oslo_service.threadgroup File "/usr/lib/python2.7/site-packages/eventlet/hubs/hub.py", line 346, in run
ERROR oslo_service.threadgroup self.wait(sleep_time)
ERROR oslo_service.threadgroup File "/usr/lib/python2.7/site-packages/eventlet/hubs/poll.py", line 85, in wait
ERROR oslo_service.threadgroup presult = self.do_poll(seconds)
ERROR oslo_service.threadgroup File "/usr/lib/python2.7/site-packages/eventlet/hubs/epolls.py", line 62, in do_poll
ERROR oslo_service.threadgroup return self.poll.poll(seconds)
ERROR oslo_service.threadgroup File "/opt/stack/f5lbaas-agent/f5_openstack_agent/lbaasv2/drivers/bigip/agent.py", line 100, in handler
ERROR oslo_service.threadgroup mgr.lbdriver.init_esd()
ERROR oslo_service.threadgroup File "/opt/stack/f5lbaas-agent/f5_openstack_agent/lbaasv2/drivers/bigip/icontrol_driver.py", line 847, in init_esd
ERROR oslo_service.threadgroup self.esd_processor.process_esd(self.get_all_bigips(), esd_dir)
ERROR oslo_service.threadgroup File "/opt/stack/f5lbaas-agent/f5_openstack_agent/lbaasv2/drivers/bigip/esd_filehandler.py", line 70, in process_esd
ERROR oslo_service.threadgroup self.esd_dict = self.verify_esd_dict(bigips, dict)
ERROR oslo_service.threadgroup File "/opt/stack/f5lbaas-agent/f5_openstack_agent/lbaasv2/drivers/bigip/esd_filehandler.py", line 137, in verify_esd_dict
ERROR oslo_service.threadgroup valid_esd = self.verify_esd(bigip, esd, esd_dict[esd])
ERROR oslo_service.threadgroup File "/opt/stack/f5lbaas-agent/f5_openstack_agent/lbaasv2/drivers/bigip/esd_filehandler.py", line 152, in verify_esd
ERROR oslo_service.threadgroup self.verify_value(bigip, tag, esd[tag])
ERROR oslo_service.threadgroup File "/opt/stack/f5lbaas-agent/f5_openstack_agent/lbaasv2/drivers/bigip/esd_filehandler.py", line 186, in verify_value
ERROR oslo_service.threadgroup is_valid = self.is_valid_value(bigip, value, resource_type)
ERROR oslo_service.threadgroup File "/opt/stack/f5lbaas-agent/f5_openstack_agent/lbaasv2/drivers/bigip/esd_filehandler.py", line 123, in is_valid_value
ERROR oslo_service.threadgroup return self.resource_exists(bigip, value, resource_type)
ERROR oslo_service.threadgroup File "/opt/stack/f5lbaas-agent/f5_openstack_agent/lbaasv2/drivers/bigip/esd_filehandler.py", line 95, in resource_exists
ERROR oslo_service.threadgroup return helper.exists_in_collection(bigip, name)
ERROR oslo_service.threadgroup File "/opt/stack/f5lbaas-agent/f5_openstack_agent/lbaasv2/drivers/bigip/resource_helper.py", line 187, in exists_in_collection
ERROR oslo_service.threadgroup collection = self.get_resources(bigip, partition='Common')
ERROR oslo_service.threadgroup File "/opt/stack/f5lbaas-agent/f5_openstack_agent/lbaasv2/drivers/bigip/resource_helper.py", line 180, in get_resources
ERROR oslo_service.threadgroup resources = collection.get_collection(requests_params=params)
ERROR oslo_service.threadgroup File "/usr/lib/python2.7/site-packages/f5_sdk-3.0.11-py2.7.egg/f5/bigip/resource.py", line 783, in get_collection
ERROR oslo_service.threadgroup self.refresh(**kwargs)
ERROR oslo_service.threadgroup File "/usr/lib/python2.7/site-packages/f5_sdk-3.0.11-py2.7.egg/f5/bigip/resource.py", line 650, in refresh
ERROR oslo_service.threadgroup self._refresh(**kwargs)
ERROR oslo_service.threadgroup File "/usr/lib/python2.7/site-packages/f5_sdk-3.0.11-py2.7.egg/f5/bigip/resource.py", line 633, in _refresh
ERROR oslo_service.threadgroup response = refresh_session.get(uri, **requests_params)
ERROR oslo_service.threadgroup File "build/bdist.linux-x86_64/egg/icontrol/session.py", line 279, in wrapper
ERROR oslo_service.threadgroup response = method(self, REST_uri, **kwargs)
ERROR oslo_service.threadgroup File "build/bdist.linux-x86_64/egg/icontrol/session.py", line 521, in get
ERROR oslo_service.threadgroup return self.session.send(prepared, **args2)
ERROR oslo_service.threadgroup File "/usr/lib/python2.7/site-packages/requests/sessions.py", line 618, in send
ERROR oslo_service.threadgroup r = adapter.send(request, **kwargs)
ERROR oslo_service.threadgroup File "/usr/lib/python2.7/site-packages/requests/adapters.py", line 440, in send
ERROR oslo_service.threadgroup timeout=timeout
ERROR oslo_service.threadgroup File "/usr/lib/python2.7/site-packages/urllib3/connectionpool.py", line 601, in urlopen
ERROR oslo_service.threadgroup chunked=chunked)
ERROR oslo_service.threadgroup File "/usr/lib/python2.7/site-packages/urllib3/connectionpool.py", line 346, in _make_request
ERROR oslo_service.threadgroup self._validate_conn(conn)
ERROR oslo_service.threadgroup File "/usr/lib/python2.7/site-packages/urllib3/connectionpool.py", line 850, in _validate_conn
ERROR oslo_service.threadgroup conn.connect()
ERROR oslo_service.threadgroup File "/usr/lib/python2.7/site-packages/urllib3/connection.py", line 284, in connect
ERROR oslo_service.threadgroup conn = self._new_conn()
ERROR oslo_service.threadgroup File "/usr/lib/python2.7/site-packages/urllib3/connection.py", line 141, in _new_conn
ERROR oslo_service.threadgroup (self.host, self.port), self.timeout, **extra_kw)
ERROR oslo_service.threadgroup File "/usr/lib/python2.7/site-packages/urllib3/util/connection.py", line 73, in create_connection
ERROR oslo_service.threadgroup sock.connect(sa)
ERROR oslo_service.threadgroup File "/usr/lib/python2.7/site-packages/eventlet/greenio/base.py", line 239, in connect
ERROR oslo_service.threadgroup self._trampoline(fd, write=True)
ERROR oslo_service.threadgroup File "/usr/lib/python2.7/site-packages/eventlet/greenio/base.py", line 203, in _trampoline
ERROR oslo_service.threadgroup mark_as_closed=self._mark_as_closed)
ERROR oslo_service.threadgroup File "/usr/lib/python2.7/site-packages/eventlet/hubs/__init__.py", line 144, in trampoline
ERROR oslo_service.threadgroup assert hub.greenlet is not current, 'do not call blocking functions from the mainloop'
ERROR oslo_service.threadgroup AssertionError: do not call blocking functions from the mainloop
ERROR oslo_service.threadgroup
我不太明白为什么会这样。
为什么不从mainloop
调用阻止功能?是因为mainloop
用于安排协程吗?
信号是否在mainloop
中触发?
有什么办法可以解决这个问题?