title: How to set the max thread a python script could use when calling from shell
body: <p>Have script a.py, it will run some task with multiple-thread, please noticed that I have no control over the a.py.</p>
  
  <p>I'm looking for a way to limit the number of thread it could use, as I found that using more threads than my CPU core will slow down the script.</p>
  
  <p>It could be something like:</p>
  
  <p>python  --nthread=2 a.py </p>
  
  <p>or Modifying something in my OS is also acceptable . </p>
  
  <p>I am using ubuntu 16.04</p>
  
  <p>As requested: </p>
  
  <p>the a.py is just a module in scikit-learn the <a href="https://github.com/scikit-learn/scikit-learn/blob/183722475189b8e21ee2e621b19acca3c9e054d8/sklearn/neural_network/multilayer_perceptron.py" rel="nofollow">MLPRegressor</a> .
  I also asked this question <a href="https://github.com/scikit-learn/scikit-learn/issues/7280" rel="nofollow">here</a>.</p>