Python分析:“ select.poll”对象的“方法'poll”是什么?

Sam*_*ufi 5 python methods profiling

我已经使用python的cProfile模块分析了我的python代码,并获得了以下结果:

   ncalls  tottime  percall  cumtime  percall filename:lineno(function)
 13937860 96351.331    0.007 96351.331    0.007 {method 'poll' of 'select.poll' objects}
 13930480  201.012    0.000  201.012    0.000 {built-in method posix.read}
 13937860  180.207    0.000 97129.916    0.007 connection.py:897(wait)
 13937860  118.066    0.000 96493.283    0.007 selectors.py:356(select)
  6968925   86.243    0.000 97360.129    0.014 queues.py:91(get)
 13937860   76.067    0.000  194.402    0.000 selectors.py:224(register)
 13937860   64.667    0.000 97194.582    0.007 connection.py:413(_poll)
 13930480   64.365    0.000  279.040    0.000 connection.py:374(_recv)
31163538/17167548   64.083    0.000  106.596    0.000 records.py:230(__getattribute__)
 13937860   57.454    0.000  264.845    0.000 selectors.py:341(register)
...
Run Code Online (Sandbox Code Playgroud)

显然,我的程序将大部分运行时间都花在上method 'poll' of 'select.poll' objects。但是,我不知道何时,为何调用此方法,以及为减少这些方法调用而必须在程序中进行的更改。

那么,我该如何寻找避免代码中出现此瓶颈的方法?

我在Linux服务器上使用numpy和sharedmem的 64位python 3.5 。

car*_*ver 10

在不同进程内执行的方法(例如使用ProcessPoolExecutor)不会被 捕获cProfile。所以这select.poll只是显示您的主进程正在等待其他进程的结果。


Mot*_*ohn 0

它是 python 库的一部分。它用于从 I/O 读取事件。根据定义,它将等待事件,因此需要更长的时间。不是你应该改变的东西。