Python Perdiodical数据获取应该使用schedueler阻止其他线程

Python Perdiodical数据获取应该使用schedueler阻止其他线程,python,multithreading,scheduler,apscheduler,Python,Multithreading,Scheduler,Apscheduler,我是python的新手。非常感谢你的帮助。让我们开始吧 我正在运行一个FLASK应用程序作为rest api。每个请求都会返回一个json。每秒可能有20个请求。在后台,我使用APscheduler每60秒从ldap获取一次实际数据 scheduler = BackgroundScheduler() scheduler.add_job( func=my_ldap.fetch_people_ldap, trigger=IntervalTrigger(seconds=60),

我是python的新手。非常感谢你的帮助。让我们开始吧

我正在运行一个FLASK应用程序作为rest api。每个请求都会返回一个json。每秒可能有20个请求。在后台,我使用APscheduler每60秒从ldap获取一次实际数据

scheduler = BackgroundScheduler()
scheduler.add_job(
    func=my_ldap.fetch_people_ldap,
    trigger=IntervalTrigger(seconds=60),
    id='fetching_data_job',
    name='Fetch data from ldap every 60 seconds')

scheduler.start()
atexit.register(lambda : scheduler.shutdown())
但实际上,当使用api调用调用datafetch时,应用程序由于内存问题而关闭,我认为这是我在调度程序调用
fetch\u people\u ldap
-函数的同时访问ldap对象的原因

我想通过阻塞处理api调用的线程来解决这个可怕的错误,直到ldap数据提取成功退出。但我不知道怎么做

有什么建议或解决方案吗

这是我获取的错误日志: 致命的Python错误:保存线程两次

Thread 0x00007f95f3fff700 (most recent call first):
  File "/path/to/folder/virtual_env_1/lib/python3.5/site-packages/pyldap-2.4.37-py3.5-linux-x86_64.egg/ldap/ldapobject.py", line 294 in _ldap_call
  File "/path/to/folder/virtual_env_1/lib/python3.5/site-packages/pyldap-2.4.37-py3.5-linux-x86_64.egg/ldap/ldapobject.py", line 721 in result4
  File "/path/to/folder/virtual_env_1/lib/python3.5/site-packages/pyldap-2.4.37-py3.5-linux-x86_64.egg/ldap/ldapobject.py", line 714 in result3
  File "/path/to/folder/virtual_env_1/lib/python3.5/site-packages/pyldap-2.4.37-py3.5-linux-x86_64.egg/ldap/ldapobject.py", line 707 in result2
  File "/path/to/folder/virtual_env_1/lib/python3.5/site-packages/pyldap-2.4.37-py3.5-linux-x86_64.egg/ldap/ldapobject.py", line 703 in result
  File "/path/to/folder/virtual_env_1/lib/python3.5/site-packages/pyldap-2.4.37-py3.5-linux-x86_64.egg/ldap/ldapobject.py", line 796 in search_ext_s
  File "/path/to/folder/virtual_env_1/lib/python3.5/site-packages/pyldap-2.4.37-py3.5-linux-x86_64.egg/ldap/ldapobject.py", line 802 in search_s
  File "/path/to/folder/tt_report_api/training_tool_report_api/sample/ldap_check/ldapCheck.py", line 49 in fetch_people_ldap
  File "/path/to/folder/virtual_env_1/lib/python3.5/site-packages/apscheduler/executors/base.py", line 125 in run_job
  File "/usr/lib/python3.5/concurrent/futures/thread.py", line 55 in run
  File "/usr/lib/python3.5/concurrent/futures/thread.py", line 66 in _worker
  File "/usr/lib/python3.5/threading.py", line 862 in run
  File "/usr/lib/python3.5/threading.py", line 914 in _bootstrap_inner
  File "/usr/lib/python3.5/threading.py", line 882 in _bootstrap

Thread 0x00007f95f8910700 (most recent call first):
  File "/usr/lib/python3.5/threading.py", line 297 in wait
  File "/usr/lib/python3.5/threading.py", line 549 in wait
  File "/path/to/folder/virtual_env_1/lib/python3.5/site-packages/apscheduler/schedulers/blocking.py", line 28 in _main_loop
  File "/usr/lib/python3.5/threading.py", line 862 in run
  File "/usr/lib/python3.5/threading.py", line 914 in _bootstrap_inner
  File "/usr/lib/python3.5/threading.py", line 882 in _bootstrap

Current thread 0x00007f9605505700 (most recent call first):
  File "/path/to/folder/virtual_env_1/lib/python3.5/site-packages/pyldap-2.4.37-py3.5-linux-x86_64.egg/ldap/ldapobject.py", line 294 in _ldap_call
  File "/path/to/folder/virtual_env_1/lib/python3.5/site-packages/pyldap-2.4.37-py3.5-linux-x86_64.egg/ldap/ldapobject.py", line 791 in search_ext
  File "/path/to/folder/virtual_env_1/lib/python3.5/site-packages/pyldap-2.4.37-py3.5-linux-x86_64.egg/ldap/ldapobject.py", line 795 in search_ext_s
  File "/path/to/folder/virtual_env_1/lib/python3.5/site-packages/pyldap-2.4.37-py3.5-linux-x86_64.egg/ldap/ldapobject.py", line 802 in search_s
  File "/path/to/folder/tt_report_api/training_tool_report_api/sample/ldap_check/ldapCheck.py", line 59 in check_node
  File "/path/to/folder/tt_report_api/training_tool_report_api/sample/ldap_check/ldapCheck.py", line 118 in build_tree_recursive
  File "/path/to/folder/tt_report_api/training_tool_report_api/sample/ldap_check/ldapCheck.py", line 124 in build_tree_recursive
  File "/path/to/folder/tt_report_api/training_tool_report_api/sample/ldap_check/ldapCheck.py", line 124 in build_tree_recursive
  File "/path/to/folder/tt_report_api/training_tool_report_api/sample/ldap_check/ldapCheck.py", line 129 in build_tree
  File "/path/to/folder/tt_report_api/training_tool_report_api/sample/app/app.py", line 83 in get_trainings_by_unit
  File "/path/to/folder/virtual_env_1/lib/python3.5/site-packages/flask/app.py", line 1598 in dispatch_request
  File "/path/to/folder/virtual_env_1/lib/python3.5/site-packages/flask/app.py", line 1612 in full_dispatch_request
  File "/path/to/folder/virtual_env_1/lib/python3.5/site-packages/flask/app.py", line 1982 in wsgi_app
  File "/path/to/folder/virtual_env_1/lib/python3.5/site-packages/flask/app.py", line 1997 in __call__
  File "/path/to/folder/virtual_env_1/lib/python3.5/site-packages/werkzeug/serving.py", line 197 in execute
  File "/path/to/folder/virtual_env_1/lib/python3.5/site-packages/werkzeug/serving.py", line 209 in run_wsgi
  File "/path/to/folder/virtual_env_1/lib/python3.5/site-packages/werkzeug/serving.py", line 267 in handle_one_request
  File "/usr/lib/python3.5/http/server.py", line 422 in handle
  File "/path/to/folder/virtual_env_1/lib/python3.5/site-packages/werkzeug/serving.py", line 232 in handle
  File "/usr/lib/python3.5/socketserver.py", line 681 in __init__
  File "/usr/lib/python3.5/socketserver.py", line 354 in finish_request
  File "/usr/lib/python3.5/socketserver.py", line 341 in process_request
  File "/usr/lib/python3.5/socketserver.py", line 313 in _handle_request_noblock
  File "/usr/lib/python3.5/socketserver.py", line 234 in serve_forever
  File "/path/to/folder/virtual_env_1/lib/python3.5/site-packages/werkzeug/serving.py", line 539 in serve_forever
  File "/path/to/folder/virtual_env_1/lib/python3.5/site-packages/werkzeug/serving.py", line 702 in inner
  File "/path/to/folder/virtual_env_1/lib/python3.5/site-packages/werkzeug/serving.py", line 739 in run_simple
  File "/path/to/folder/virtual_env_1/lib/python3.5/site-packages/flask/app.py", line 841 in run
  File "/path/to/folder/tt_report_api/training_tool_report_api/sample/app/app.py", line 92 in <module>

Process finished with exit code 134 (interrupted by signal 6: SIGABRT)
线程0x00007f95f3fff700(最新调用优先):
文件“/path/to/folder/virtual_env_1/lib/python3.5/site packages/pyldap调用中的第294行“/pyldap-2.4.37-py3.5-linux-x86_64.egg/ldap/ldapobject.py”
文件“/path/to/folder/virtual_env_1/lib/python3.5/site packages/pyldap-2.4.37-py3.5-linux-x86_64.egg/ldap/ldapobject.py”,结果4中的第721行
文件“/path/to/folder/virtual_env_1/lib/python3.5/site packages/pyldap-2.4.37-py3.5-linux-x86_64.egg/ldap/ldapobject.py”,结果3中的第714行
文件“/path/to/folder/virtual_env_1/lib/python3.5/site packages/pyldap-2.4.37-py3.5-linux-x86_64.egg/ldap/ldapobject.py”,结果2中第707行
文件“/path/to/folder/virtual_env_1/lib/python3.5/site packages/pyldap-2.4.37-py3.5-linux-x86_64.egg/ldap/ldapobject.py”,结果中的第703行
文件“/path/to/folder/virtual_env_1/lib/python3.5/site packages/pyldap-2.4.37-py3.5-linux-x86_64.egg/ldap/ldapobject.py”,搜索扩展中的第796行
文件“/path/to/folder/virtual_env_1/lib/python3.5/site packages/pyldap-2.4.37-py3.5-linux-x86_64.egg/ldap/ldapobject.py”,搜索中的第802行
文件“/path/to/folder/tt_report_api/training_tool_report_api/sample/ldap_check/ldapCheck.py”,fetch_people_ldap中的第49行
文件“/path/to/folder/virtual_env_1/lib/python3.5/site packages/apscheduler/executors/base.py”,运行作业中的第125行
文件“/usr/lib/python3.5/concurrent/futures/thread.py”,运行中的第55行
文件“/usr/lib/python3.5/concurrent/futures/thread.py”,第66行
文件“/usr/lib/python3.5/threading.py”,运行中的第862行
文件“/usr/lib/python3.5/threading.py”,bootstrap\u inner中的第914行
文件“/usr/lib/python3.5/threading.py”,bootstrap中的第882行
线程0x00007f95f8910700(最新调用优先):
文件“/usr/lib/python3.5/threading.py”,第297行正在等待
文件“/usr/lib/python3.5/threading.py”,第549行正在等待
文件“/path/to/folder/virtual_env_1/lib/python3.5/site packages/apscheduler/schedulers/blocking.py”,主循环第28行
文件“/usr/lib/python3.5/threading.py”,运行中的第862行
文件“/usr/lib/python3.5/threading.py”,bootstrap\u inner中的第914行
文件“/usr/lib/python3.5/threading.py”,bootstrap中的第882行
当前线程0x00007f9605505700(最新调用优先):
文件“/path/to/folder/virtual_env_1/lib/python3.5/site packages/pyldap调用中的第294行“/pyldap-2.4.37-py3.5-linux-x86_64.egg/ldap/ldapobject.py”
文件“/path/to/folder/virtual_env_1/lib/python3.5/site packages/pyldap-2.4.37-py3.5-linux-x86_64.egg/ldap/ldapobject.py”,搜索文本第791行
文件“/path/to/folder/virtual_env_1/lib/python3.5/site packages/pyldap-2.4.37-py3.5-linux-x86_64.egg/ldap/ldapobject.py”,搜索扩展中的第795行
文件“/path/to/folder/virtual_env_1/lib/python3.5/site packages/pyldap-2.4.37-py3.5-linux-x86_64.egg/ldap/ldapobject.py”,搜索中的第802行
文件“/path/to/folder/tt_report_api/training_tool_report_api/sample/ldap_check/ldapCheck.py”,检查节点中的第59行
文件“/path/to/folder/tt_report_api/training_tool_report_api/sample/ldap_check/ldapCheck.py”,构建树中的第118行
文件“/path/to/folder/tt_report_api/training_tool_report_api/sample/ldap_check/ldapCheck.py”,构建树中的第124行
文件“/path/to/folder/tt_report_api/training_tool_report_api/sample/ldap_check/ldapCheck.py”,构建树中的第124行
文件“/path/to/folder/tt_report_api/training_tool_report_api/sample/ldap_check/ldapCheck.py”,构建树中的第129行
文件“/path/to/folder/tt_report_api/training_tool_report_api/sample/app/app.py”,按单元获取培训中的第83行
文件“/path/to/folder/virtual_env_1/lib/python3.5/site packages/flask/app.py”,调度请求中的第1598行
文件“/path/to/folder/virtual_env_1/lib/python3.5/site packages/flask/app.py”,完整调度请求中的第1612行
文件“/path/to/folder/virtual_env_1/lib/python3.5/site packages/flask/app.py”,wsgi_应用程序中的第1982行
文件“/path/to/folder/virtual_env_1/lib/python3.5/site packages/flask/app.py”,调用中的第1997行__
文件“/path/to/folder/virtual_env_1/lib/python3.5/site packages/werkzeug/service.py”,执行中的第197行
文件“/path/to/folder/virtual_env_1/lib/python3.5/site packages/werkzeug/service.py”,run_wsgi中的第209行
文件“/path/to/folder/virtual_env_1/lib/python3.5/site packages/werkzeug/service.py”,handle_one_请求第267行
文件“/usr/lib/python3.5/http/server.py”,句柄中的第422行
文件“/path/to/folder/virtual_env_1/lib/python3.5/site packages/werkzeug/service.py”,handle中的第232行
文件“/usr/lib/python3.5/socketserver.py”,初始化中的第681行__
文件“/usr/lib/python3.5/socketserver.py”,完成请求中的第354行
文件“/usr/lib/python3.5/socketserver.py”,处理请求中的第341行
文件“/usr/lib/python3.5/socketserver.py”,处理请求noblock中的第313行
文件“/usr/lib/python3.5/socketserver.py”,第234行
文件“/path/to/folder/virtual_env_1/lib/python3.5/site packages/werkzeug/serving.py”,永远服务中的第539行
文件“/path/to/folder/virtual_env_1/lib/python3.5/site-packages/werkzeug/s
Current thread 0x00007f9605505700 (most recent call first):
  File "/path/to/folder/virtual_env_1/lib/python3.5/site-packages/pyldap-2.4.37-py3.5-linux-x86_64.egg/ldap/ldapobject.py", line 294 in _ldap_call
...
  File "/path/to/folder/tt_report_api/training_tool_report_api/sample/ldap_check/ldapCheck.py", line 124 in build_tree_recursive
...
File "/path/to/folder/tt_report_api/training_tool_report_api/sample/app/app.py", line 83 in get_trainings_by_unit
...
  File "/path/to/folder/virtual_env_1/lib/python3.5/site-packages/flask/app.py", line 841 in run
Thread 0x00007f95f3fff700 (most recent call first):
  File "/path/to/folder/virtual_env_1/lib/python3.5/site-packages/pyldap-2.4.37-py3.5-linux-x86_64.egg/ldap/ldapobject.py", line 294 in _ldap_call
...
  File "/path/to/folder/tt_report_api/training_tool_report_api/sample/ldap_check/ldapCheck.py", line 49 in fetch_people_ldap
...
  File "/usr/lib/python3.5/threading.py", line 882 in _bootstrap