All jobs

Fix "AttributeError: 'Thread' object has no attribute 'isAlive'" on Python 3.9+

Yes. An agent renames each isAlive call to is_alive, writes a test for the path that hid it from CI, and opens a pull request.

Run this on RushOpens the console with this prompt ready to send, in a Project that has your repository.

What the agent does

Thread.isAlive() was the camelCase spelling of is_alive() kept from Python 2. Python 3.8 warns on every call, isAlive() is deprecated, use is_alive() instead, and Python 3.9 removed the method. The fix is a rename. What deserves attention is why the call survives in code that has tests and a CI matrix, and revdotcom/revai-python-sdk answers that well. The SDK is maintained, its setup.py classifiers list Python 3.8 to 3.11, and .github/workflows/build_test.yml tests those four versions. Yet line 158 of src/rev_ai/streamingclient.py reads if self.request_thread.isAlive():.

The agent reads the lines around it to find when it runs. _start_send_data_thread first checks hasattr(self, 'request_thread'). The attribute is only set further down, when the thread is created, so the isAlive() call is skipped the first time a client starts streaming and reached the second time start() is called on the same RevAiStreamingClient. Its purpose is to raise a RuntimeError saying data is still being sent. The tests in tests/test_streamingclient.py build a fresh client from the mock_streaming_client fixture for each test and call start() once. On Python 3.11 all 165 tests pass. The line is broken on three of the four versions in the matrix and no test can tell.

So the agent writes the test before the fix. It uses the same fixture, starts the client with the mock generator, lets the sending thread finish, and calls start() again. On Python 3.11 and 3.12 the second call raises the title's AttributeError; on 3.8 it passes with the deprecation warning. Then it changes isAlive() to is_alive(), which has existed since Python 2.6, so no supported version needs a fallback, and the test passes everywhere. A second test covers the branch the check exists for: a generator that blocks keeps the first thread alive, and the second start() must raise the RuntimeError about data still being sent.

Last, it looks at how to stop the next removal from hiding the same way. Python 3.8 warns about this method, and the suite runs on 3.8 without anyone seeing the warning, because the line never executes there either. The agent greps for other deprecated threading spellings such as setDaemon, getName and currentThread, reports what it finds, and proposes turning DeprecationWarning into an error in the pytest configuration as a separate change, since doing so may surface warnings from dependencies that need their own decisions.

Start it with one API call

POST https://api.phoenix.so/o/{org}/sessions with this body:

{
  "agent": "claude",
  "input": "This project fails on Python 3.9 or later with \"AttributeError: 'Thread' object has no attribute 'isAlive'\". Fix it. Find every call to isAlive on a threading.Thread or a subclass, and check for other camelCase threading methods that are deprecated (setDaemon, isDaemon, getName, setName, currentThread, activeCount, notifyAll). For each isAlive call, read the surrounding code and work out under what conditions it executes. Check whether the existing tests reach it on any Python version; if they do not, explain why CI stayed green, and write a test that reaches it using the project's existing fixtures. Show that test failing with the AttributeError on the newest Python the project supports before the change. Replace isAlive() with is_alive() and do not add a compatibility shim unless the project's metadata still declares Python 2.5 or older. Add a test for the behaviour the liveness check protects, not only for the absence of the error. Run the full suite on the oldest and newest Python in the project's CI matrix or classifiers and report both. Report other deprecated threading calls with file and line without changing them, and say whether making DeprecationWarning an error in the test configuration would have caught this. Open a pull request.",
  "resources": [
    {
      "url": "https://github.com/your-org/your-app"
    }
  ]
}
  1. Get an API key. In the console, open Settings, then API keys, and create a key for your org. Send it in the Authorization header as a Bearer token.
  2. Send the request. POST the body in request.json to https://api.phoenix.so/o/{org}/sessions, with your repository as the resources URL. The run starts in its own cloud sandbox.
  3. Read what came back. Follow the run on its live stream or wait for the run.completed webhook, then read the result and its trajectory.

What comes back

A pull request with a one-word change in the source and two new tests. The description explains the condition that reaches the line, in the SDK's case a second start() on one client, and shows the first new test failing with the AttributeError before the change on the newest supported Python and passing after it. The second test's result shows that the guard still does its job and raises when the first thread is alive.

The suite's totals are given for the oldest and newest Python the project claims, so the reviewer sees that nothing else moved. Other deprecated spellings the grep found are listed with file and line and left for a follow-up, and the suggestion about failing tests on DeprecationWarning comes with a count of the warnings that setting would raise today.

What a reviewer adds is knowledge the code does not hold: whether callers really restart one client, and so how many users this affected. For a published SDK the description also notes that the fix needs a release to reach them and that the change is safe for a patch version, since it only repairs a path that could not work.

Run it on every weekday morning

A latent call like this one produces no alert until a user finds it, so run the check on a clock instead of waiting. Create an automation in the Project with a schedule trigger, for example the cron 0 7 * * 1-5 with the timezone your team works in, and save a version of this prompt that covers every deprecated standard-library call and not only this one. Each fire starts a run in the Project's repository.

Most mornings the right result is a short report that nothing new was found, so tell the prompt to open a pull request only when a test it wrote fails on a supported Python. If you would rather review findings before any branch exists, switch the automation to read only: its runs can read the repository and comment but not push. Turning the automation off and on again moves the schedule to its next slot and does not replay the mornings it missed.

The use case this job follows, with its automation and trigger: Fix a bug from an alert.

Why run it on Rush?

This bug is invisible to the tools a team already has. The CI matrix covers the right Pythons and stays green, because coverage of versions is not coverage of lines. Finding it takes reading for the condition and then building a test that meets it on several interpreters. In its own sandbox the agent installs the oldest and newest Python the project supports and runs the new test on each, and the transcript keeps both outputs: the warning on 3.8 and the error on 3.11.

A person would more likely fix the line by search and replace and move on, which leaves the question of why it was missed unanswered and the guard itself untested. A run whose instructions demand a failing test first and a test of the protected behaviour second leaves the repository better covered than it found it. The pull request arrives with that evidence attached, so review is a matter of reading two test results.

Frequently asked questions

What replaced Thread.isAlive()?

Thread.is_alive(). It returns the same boolean and has been available since Python 2.6, so replacing the call does not narrow the versions your code supports. Python 3.9 removed the old name after warning about it in 3.8.

Why did my tests pass on Python 3.9 and later if the method is gone?

Because no test executed the line. An attribute lookup on a missing method only fails when it runs. In the SDK example the call sits behind a check that is false the first time a client starts, and every test starts each client once.

The error comes from a package I installed. Can the agent still help?

Yes. It reads the traceback, identifies the package and version, and looks for a release that uses is_alive(). The pull request bumps the dependency and shows the failing path working. If the package is abandoned, the result says so and names maintained alternatives it found.

Should I make DeprecationWarning an error in my tests?

It is a good default for your own code, and the agent reports what it would raise today before you turn it on. It would not have caught this exact case, where the line never ran under test. It catches the deprecated calls your tests do reach, a release or two before they are removed.

Does the agent rename setDaemon and getName as well?

It reports them and leaves them. Those spellings are deprecated but still present in current Python releases, so they are not causing the error in the title. Keeping the pull request to the broken call makes it easy to review and safe to release quickly.

More jobs like this: Fix a bug from an alert

Keep reading