无法匹配金字塔生成的线程tid和tid。

时间:2017-03-08 11:19:36

标签: multithreading pyramid pyramid-debug-toolbar

导入线程

def worker():

    """thread worker function"""

    print threading.currentThread().ident

    return

I = 0

而我< 5:

    t.start()

    i=i+1

输出:

1972960112

1989745520

1998134128

1939389296

1981356912

然而,金字塔日志提供了一套单独的tid .. 喜欢... ...

1807137648

1763703664

1780480880

1832303472

1797258096

任何人都可以帮助我生成与金字塔服务器greps相同的tid。任何线索或方向都是受欢迎的。

1 个答案:

答案 0 :(得分:0)

如果我使用pyramid-cookiecutter-starter模板启动一个新项目并修改日志记录,以便我输出线程ident,那么一切都按预期匹配。

cookiecutter gh:Pylons/pyramid-cookiecutter-starter
cd scaffold
python3 -m venv env
env/bin/pip install -e .
# edit files as below
env/bin/pserve development.ini
# open browser and visit http://localhost:6543/

# views.py
from pyramid.view import view_config
import threading

log = __import__('logging').getLogger(__name__)

@view_config(route_name='home', renderer='templates/mytemplate.jinja2')
def my_view(request):
    log.info('hello from thread=%s', threading.currentThread().ident)
    return {'project': 'Pyramid Scaffold'}


# development.ini
[formatter_generic]
format = %(asctime)s %(levelname)-5.5s [%(name)s:%(lineno)s][%(thread)s] %(message)s


2017-03-09 13:47:14,996 INFO  [scaffold.views:8][123145480736768] hello from thread=123145480736768
2017-03-09 13:47:17,145 INFO  [scaffold.views:8][123145489149952] hello from thread=123145489149952
2017-03-09 13:47:17,504 INFO  [scaffold.views:8][123145480736768] hello from thread=123145480736768
2017-03-09 13:47:17,745 INFO  [scaffold.views:8][123145489149952] hello from thread=123145489149952
2017-03-09 13:47:17,945 INFO  [scaffold.views:8][123145480736768] hello from thread=123145480736768
2017-03-09 13:47:18,138 INFO  [scaffold.views:8][123145484943360] hello from thread=123145484943360
2017-03-09 13:47:18,311 INFO  [scaffold.views:8][123145489149952] hello from thread=123145489149952
2017-03-09 13:47:18,496 INFO  [scaffold.views:8][123145493356544] hello from thread=123145493356544
2017-03-09 13:47:18,717 INFO  [scaffold.views:8][123145480736768] hello from thread=123145480736768
2017-03-09 13:47:18,846 INFO  [scaffold.views:8][123145489149952] hello from thread=123145489149952

我需要你提供一个可重复的例子,就像我在这里一样,了解你实际要问的内容。