How to limit number of threads for python interpreter?











up vote
2
down vote

favorite
1












I want to know whether it is possible to limit the number of threads python interpreter can spawn when running a script.



I am not using threading myself, but my script uses modules like pandas, numpy, and others which I assume would be using threading in the background. The script works fine, but when I run it on an LSF cluster, it spawns too many threads crossing thread limit per job (for the cluster) and as a result, crashes.



I would like to restrict the python interpreter to not allow more than, say, 100, threads at a time. Is it possible to run a python script on an LSF server with such a restriction on thread count?



Thanks for your help.



P.S.: My colleague faces the same issue with java apps, so a solution for that would be cool as well.










share|improve this question






















  • Are you using vanilla python to run scripts? Are you aware of the Python GIL ? Also, see stackoverflow.com/questions/30791550/…
    – RottenCandy
    Nov 8 at 10:30

















up vote
2
down vote

favorite
1












I want to know whether it is possible to limit the number of threads python interpreter can spawn when running a script.



I am not using threading myself, but my script uses modules like pandas, numpy, and others which I assume would be using threading in the background. The script works fine, but when I run it on an LSF cluster, it spawns too many threads crossing thread limit per job (for the cluster) and as a result, crashes.



I would like to restrict the python interpreter to not allow more than, say, 100, threads at a time. Is it possible to run a python script on an LSF server with such a restriction on thread count?



Thanks for your help.



P.S.: My colleague faces the same issue with java apps, so a solution for that would be cool as well.










share|improve this question






















  • Are you using vanilla python to run scripts? Are you aware of the Python GIL ? Also, see stackoverflow.com/questions/30791550/…
    – RottenCandy
    Nov 8 at 10:30















up vote
2
down vote

favorite
1









up vote
2
down vote

favorite
1






1





I want to know whether it is possible to limit the number of threads python interpreter can spawn when running a script.



I am not using threading myself, but my script uses modules like pandas, numpy, and others which I assume would be using threading in the background. The script works fine, but when I run it on an LSF cluster, it spawns too many threads crossing thread limit per job (for the cluster) and as a result, crashes.



I would like to restrict the python interpreter to not allow more than, say, 100, threads at a time. Is it possible to run a python script on an LSF server with such a restriction on thread count?



Thanks for your help.



P.S.: My colleague faces the same issue with java apps, so a solution for that would be cool as well.










share|improve this question













I want to know whether it is possible to limit the number of threads python interpreter can spawn when running a script.



I am not using threading myself, but my script uses modules like pandas, numpy, and others which I assume would be using threading in the background. The script works fine, but when I run it on an LSF cluster, it spawns too many threads crossing thread limit per job (for the cluster) and as a result, crashes.



I would like to restrict the python interpreter to not allow more than, say, 100, threads at a time. Is it possible to run a python script on an LSF server with such a restriction on thread count?



Thanks for your help.



P.S.: My colleague faces the same issue with java apps, so a solution for that would be cool as well.







java python multithreading hpc lsf






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 8 at 10:03









Manish Goel

341213




341213












  • Are you using vanilla python to run scripts? Are you aware of the Python GIL ? Also, see stackoverflow.com/questions/30791550/…
    – RottenCandy
    Nov 8 at 10:30




















  • Are you using vanilla python to run scripts? Are you aware of the Python GIL ? Also, see stackoverflow.com/questions/30791550/…
    – RottenCandy
    Nov 8 at 10:30


















Are you using vanilla python to run scripts? Are you aware of the Python GIL ? Also, see stackoverflow.com/questions/30791550/…
– RottenCandy
Nov 8 at 10:30






Are you using vanilla python to run scripts? Are you aware of the Python GIL ? Also, see stackoverflow.com/questions/30791550/…
– RottenCandy
Nov 8 at 10:30



















active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














 

draft saved


draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53205405%2fhow-to-limit-number-of-threads-for-python-interpreter%23new-answer', 'question_page');
}
);

Post as a guest





































active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes
















 

draft saved


draft discarded



















































 


draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53205405%2fhow-to-limit-number-of-threads-for-python-interpreter%23new-answer', 'question_page');
}
);

Post as a guest




















































































Popular posts from this blog

Schultheiß

Verwaltungsgliederung Dänemarks

Liste der Kulturdenkmale in Wilsdruff