title: 10 s delay time for time.sleep in ipython after matplotlib 3.x.x import
body: <p>I realize that time.sleep() calls the OS timer and can vary a little (as this <a href="https://stackoverflow.com/questions/25355257/pythons-time-sleep-method-waits-incorrect-amount-of-time">answer</a> points out), but I am seeing a very large delay time in Ipython. This seems to just happen after I have imported matplotlib.pyplot. Then right after waiting about 30 seconds, it starts to lag. To give a working example, try entering iPython:</p>
  
  <pre><code>&gt;&gt;import matplotlib.pyplot as plt
  # after 30 seconds
  &gt;&gt;%time time.sleep(1)                                                        
  CPU times: user 5.27 ms, sys: 3.58 ms, total: 8.85 ms
  Wall time: 11 s
  </code></pre>
  
  <p>Using slightly longer times in sleep appears to have an additive effect:</p>
  
  <pre><code>&gt;&gt;%time time.sleep(3)                                                        
  CPU times: user 4.75 ms, sys: 3.7 ms, total: 8.45 ms
  Wall time: 13 s
  </code></pre>
  
  <p>Very occasionally the wall time is appropriate, but only about 1/10 of the time. I also tried boxing the sleep in a function as follows:</p>
  
  <pre><code>&gt;&gt;def test(): 
       start = time.time() 
       for i in range(4): 
           time.sleep(1) 
           print(f'{time.time() - start}')
  
  &gt;&gt;test()                                                                
  11.000279188156128
  22.000601053237915
  33.000962018966675
  44.001291036605835
  </code></pre>
  
  <p>This also occasionally shows smaller time steps, but this is the usual output. I also put the same function in a separate file and used %run script.py in iPython, with the same result. Thus, it happens anytime time.sleep is called.</p>
  
  <p>The only things that seems to work are (a) not importing matplotlib.pyplot</p>
  
  <p>or (b) defining a function based on a simple all-python timer:</p>
  
  <pre><code>&gt;&gt;def dosleep(t): 
       start = time.time() 
       while time.time() - start &lt; t: 
           continue
  
  &gt;&gt;%time dosleep(2)                                                      
  CPU times: user 1.99 s, sys: 8.4 ms, total: 2 s
  Wall time: 2 s
  </code></pre>
  
  <p>The last example seems like a good solution, but I have a decent amount of code that relies on time.sleep() already, and I would like to still use Jupyter with an Ipython kernel. Is there any way to determine what is holding it up, or are there any tips on how to decrease the lag time? I'm just wondering what sort of thing could cause this.</p>
  
  <p>I'm on Mac OS X 10.14.3, running Python 3.6.8 (Anaconda). My Ipython version is 7.3.0. It works the same for iPython 7.4.0. The matplotlib version is 3.0.3. The problem does not occur until the interactive GUI system is interacted (which is immediately at the import for matplotlib 3.x and at the creation of a figure (plt.figure()) with matplotlib 2.x). It occurs when an icon appears in the dock called "Python 3.6".</p>