2

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"?

Community
  • 1
  • 1
Zauberin Stardreamer
  • 1,284
  • 1
  • 13
  • 22

1 Answers1

1

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.

Michael
  • 13,244
  • 23
  • 67
  • 115