Dinesh Pundkar Dinesh Pundkar - 1 month ago 11
Python Question

Why two methods with same functionality available in threading module in Python?

For

threading.Thread
, there are two methods which seems to have same functionality :


  • is_alive
    and
    isAlive



For
threading.Event
, there is below method :


  • is_set
    and
    isSet



Similarly
threading
module , again these methods are available


  • currentThread
    and
    current_thread

  • active_count
    and
    activeCount



So, question is, though it seems, both the methods have same functionality, why there are two methods available?

Also, which one is preferable ?

Answer

Python, as a rule, uses lowercase or lowercase_with_underscores for method and function names. The threading module incorrectly used mixedCase for many of the names when first added to Python. They later added the lowercase_with_underscores names as aliases for style consistency with the rest of Python.

In general, use the lowercase_with_underscores names unless your code needs to run on Python 2.5 or earlier (the fixed names were added in 2.6). That said, the docs note:

Note: Starting with Python 2.6, this module provides PEP 8 compliant aliases and properties to replace the camelCase names that were inspired by Java’s threading API. This updated API is compatible with that of the multiprocessing module. However, no schedule has been set for the deprecation of the camelCase names and they remain fully supported in both Python 2.x and 3.x.

Comments