1

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 ?

1

3 Answers 3

2

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.

Sign up to request clarification or add additional context in comments.

Comments

2

It is a matter of style. Before underscore style was officially accepted as Python's style there were libraries already using different style. So functions were renamed but due to compatibility issues old name versions had to be kept as well.

Anyway PEP 8 suggests to use underscore style so I advice sticking with it.

Comments

1

I am not 100% sure but its just aliases from different versions of Python i think and they have same function

The reason is to keep compatibility with olders version of Python

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.