What does {method 'poll' of 'select.poll'…} mean in cprofile output?

Question:

I have a flask app that I’m trying to profile (I’m new to this). When I ran it, I had this result:

3327 function calls (3247 primitive calls) in 7.350 seconds

   Ordered by: cumulative time

   ncalls  tottime  percall  cumtime  percall filename:lineno(function)
      7/1    0.000    0.000    7.350    7.350 {built-in method builtins.exec}
        1    0.000    0.000    7.350    7.350 <string>:1(<module>)
        1    0.000    0.000    7.350    7.350 vo_app_v2.py:1094(run_app)
        1    0.000    0.000    7.350    7.350 app.py:1064(run)
        1    0.000    0.000    7.349    7.349 serving.py:936(run_simple)
        1    0.000    0.000    7.348    7.348 serving.py:739(serve_forever)
        1    0.000    0.000    7.348    7.348 socketserver.py:215(serve_forever)
       15    0.000    0.000    7.347    0.490 selectors.py:403(select)
       15    7.347    0.490    7.347    0.490 {method 'poll' of 'select.poll' objects}

What does the last line mean? How do I trace it to the line in my code?

Asked By: Mike Mann

||

Answers:

poll() is a newer syscall that replaces an older interface called select() (the even newer Linux-specific version is called epoll()). All of the interfaces in this family are about I/O — allowing a single thread to efficiently wait on multiple file descriptors until one of them is ready to read from or write to and then be woken up when one of these FDs is ready for work to be done on it.

As such, this is not about a line of your code; it’s a line of Python standard-library code. And specifically, it’s waiting for I/O — whether disk or network is unclear, but basically it’s either waiting for data to come in, or for a network connection (or a disk) to stop being busy so data can be sent (or written); and specifically doing so in a context where a single thread can potentially be called on to handle events related to any of several files or network connections.

In general, then, this isn’t a place where your code is being slow, but a place where your code is stuck waiting for something else.

Answered By: Charles Duffy
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.