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 ?

Dinesh Pundkar
  • 4,160
  • 1
  • 23
  • 37
  • it's just backwards naming compatibility. Use the lowercase+underscore version from now on: http://stackoverflow.com/questions/919897/how-to-find-a-thread-id-in-python – Jean-François Fabre Oct 31 '16 at 14:59

3 Answers3

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.

freakish
  • 54,167
  • 9
  • 132
  • 169
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.

ShadowRanger
  • 143,180
  • 12
  • 188
  • 271
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

Erik Šťastný
  • 1,487
  • 1
  • 15
  • 41