pythonmultithreadingpython-2.7python-stackless

Sleep instead of thread.join() for platform legacy reasons


Working on a git fork of someone's code, I came across the following, there to halt the master thread until such a time as all the sub-threads are done:

while(True):
    if not any([thread.isAlive() for thread in self.threads]):
        break
    else:
        time.sleep(1)

This seemed to me to be a waste of processor time; it would be simpler and less processor intensive to just wait to .join() the sub-threads.

Here I should note that all subthreads were set to be "daemons" at the time of creation.

I replaced this code with my own:

# Luckily, threading.join() works just fine.
for thread in self.threads:
    thread.join()

When I issued a pull request, I was told "Will not merge commit XYZ, sleep is in there for platform legacy reasons."

What kind of legacy reasons could lead to this verbosity being required? He didn't complain about my use of .join() anywhere else, just for that one task.

EDIT

Argument was made by the person who revoked my pull request that Stackless Python's join() works slightly differently from the default. I don't see it in the docs, but perhaps it is true. Docs are here, and look identical to the behavior my implementation assumes, however that's the perspective of the project owner.


Solution

  • It turns out that the maintainer had his own custom patched version of stackless python that broke the API on one of his computers.