multithreadingpyramidpyramid-debug-toolbar

unable to match thread tid and tid generated by pyramid.


import threading

def worker():

    """thread worker function"""

    print threading.currentThread().ident

    return

i=0

while i<5:

    t.start()

    i=i+1

output:

1972960112

1989745520

1998134128

1939389296

1981356912

However, the pyramid logs give a seperate set of tid.. Someting like...

1807137648

1763703664

1780480880

1832303472

1797258096

Can anyone help me generate the same tid as the pyramid server greps. Any clue or direction is welcome.


Solution

  • If I start a new project using the pyramid-cookiecutter-starter template and modify the logging such that I output the thread ident then everything matches as expected.

    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
    

    I'd need you to provide a reproducible example, as I have here, to understand what you're actually asking.