Zauberin Stardreamer
Zauberin Stardreamer

Reputation: 1344

Tell if python allows threading from within a python script

Is there any way for a python script to detect whether or not it is allowed to use threading? I'm currently writing a wiki engine, and I would like for it to be able to take advantage of threading. However, not all hosting environments allow python scripts to use threading (for example, free accounts at PythonAnywhere), so I would like for the script to be able to detect this and disable threaded mode on such environments.

NOTE: I have already checked the question below, and it is not a duplicate of my question, as it addresses a different topic: Is there a way to tell if python was configured and compiled with "--with-threads --enable-shared"?

Upvotes: 2

Views: 208

Answers (1)

Michael
Michael

Reputation: 13914

Add a try statement at the beginning of your script that asserts a piece of code that requires multithreading. If it fails, make a change in the except block to a logical indicator for whether or not the script should use multithreading.

Upvotes: 1

Related Questions