# Fix "AttributeError: module 'tornado.web' has no attribute 'asynchronous'" after a Tornado upgrade

Yes. An agent rewrites each @tornado.web.asynchronous handler as a coroutine that awaits its background work, then proves the route answers on Tornado 6.

[Run this on Rush](https://cloud.getrush.ai/run/fix-tornado-web-asynchronous-attribute-error/tornado/). Opens the console with this prompt ready to send, in a Project that has your repository.

## What the agent does

The agent reads the handler that carries the decorator. In oduwsdl/CarbonDate, a service that estimates when a web page was first published, `server.py` defines `CarbonDateServer`, a `tornado.web.RequestHandler` whose `get` method sits under `@tornado.web.asynchronous` on line 27. The method hands the real work to `run_background`, which uses a `multiprocessing.pool.ThreadPool(50)` and `apply_async`, and the completion callback `on_complete` writes the JSON result and calls `self.finish()`. The `start` function below it builds the application with one `/cd/(.*)` route and a `StaticFileHandler` for `docs`, and listens on the port from `config` unless `CD_Server_port` or `PORT` is set. `main.py -s` calls `server.start(args, cfg, mod)` with a `core.ModuleManager`, whose `run` method starts one thread per module in `modules/`, ten of them, joins each with the `--timeout` value, and assembles `uri`, `estimated-creation-date`, `earliest-sources` and `sources`.

Then it reads how the project pins things. `requirements.txt` says `tornado>=5.0.0,<6.0.0`, the `Dockerfile` is `FROM python:3.9`, and `.travis.yml` still names Python 3.4. On Python 3.11 the pin installs Tornado 5.1.1 and `import server` fails before this handler is reached, with `AttributeError: module 'collections' has no attribute 'MutableMapping'` from inside Tornado itself. That is the first thing a developer on a current Python sees, and the natural response is to lift the upper bound. With it gone, pip installs Tornado 6.6 and `import server` fails on line 27 with the error in the title, because a decorator on a class method runs when the module is imported, before any request arrives.

The boundary is Tornado 6.0, published 2019-03-01: 6.0.4 has no `tornado.web.asynchronous` and 5.1.1 still has it. The agent also records which Tornado 6 fits the project's Python: 6.4.2 requires Python 3.8 or newer, 6.5.2 requires 3.9, and 6.6 requires 3.11, so a repository that keeps `python:3.9` as its base image can go to 6.5.2 and no further, and the pull request says that beside the requirement change.

The rewrite keeps the thread pool and drops the callback. `get` becomes `async def get`, and the work the old code pushed through `apply_async` is awaited with `IOLoop.current().run_in_executor`, passing `functools.partial(self.modLoader.run, args=..., resultDict=..., logger=..., url=...)` so the module manager is called exactly as before. `multiprocessing.pool.ThreadPool` becomes `concurrent.futures.ThreadPoolExecutor(50)`, which is what `run_in_executor` takes, `run_background` is deleted, and `on_complete` is called with the awaited result and left otherwise as it was, including `self.finish()`. To prove it, the agent writes a `tornado.testing.AsyncHTTPTestCase` that mounts `CarbonDateServer` with a stub module loader, fetches `/cd/http://example.com/`, and checks for a 200, a JSON body whose `uri` is the requested address, and a `Content-Type` of `application/json`. It also runs the repository's own tests that need no network, `tests/test_getLowest.py` and `tests/test_pubdate.py`, which pass on Tornado 6, and leaves the ones that call live archives and search APIs to the reviewer.

## Start it with one API call

`POST https://api.phoenix.so/o/{org}/sessions`

```json
{
  "agent": "claude",
  "input": "Our Tornado service fails at import with \"AttributeError: module 'tornado.web' has no attribute 'asynchronous'\" after the Tornado upper bound was lifted. Find every handler method decorated with @tornado.web.asynchronous, every @tornado.gen.engine, and every use of a callback argument to fetch or to a thread pool with a completion callback. Read the dependency file, the Dockerfile and CI config to say which Tornado and which Python the project pins, confirm by installing them which Tornado release removed the decorator, and say which Tornado 6 releases support the project's Python version. Rewrite each decorated handler as an async method that awaits its background work through the IOLoop's run_in_executor, keeping the same thread pool size, the same response body, headers and status, and the same finish behaviour. Do not change what the modules compute. Prove it with a tornado.testing test that mounts the handler with a stub for the slow work and checks the status, body and content type, and run whatever of the existing test suite needs no network. Open a pull request with the diff, the version findings and the test output.",
  "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 that touches `server.py` and `requirements.txt`. In `server.py` the import of `ThreadPool` becomes `ThreadPoolExecutor`, `get` is an `async def` that awaits `run_in_executor` and then calls the unchanged `on_complete`, and the `run_background` method is gone, along with the decorator. `requirements.txt` moves the Tornado bound to a 6.x range that the Dockerfile's Python can install. The description states the two errors in the order a developer meets them, the pinned-5.1.1 import failure on a current Python and then the decorator error on 6.6, the release boundary, and the Python requirement of each Tornado 6 release considered.

Below that is the test: the new `AsyncHTTPTestCase` with its stub loader and the 200 JSON response it checks, and the output of the existing test files that ran. The reviewer checks three things in the diff: that the awaited call passes the same keyword arguments `ModuleManager.run` reads (`args`, `resultDict`, `logger`, `url`), that the handler still finishes exactly once, and that the module timeout the old code relied on, the `join(timeout)` inside `run`, is untouched, so a slow archive still cannot hold a request open forever.

What the run does not prove is a real date estimate. The ten modules query web archives, search engines and link shorteners, and some need the Bing and Bitly keys named in `config`, so the sandbox exercises the handler with a stub and leaves a live `/cd/` request to the reviewer's deployment.

## Run it on every base image upgrade that breaks start-up

This error surfaces when the Python base image moves, because the old Tornado pin stops importing first and the fix for that is what exposes the removed decorator. A CI job that builds the image and starts the service can send its log tail, on failure, to a Rush `webhook` trigger's URL with the trigger's secret in `Authorization: Bearer`; the log lands after the saved prompt as the event, so the prompt tells the agent to read the traceback from it. Send an `Idempotency-Key` header to the trigger's URL set to the image tag, so a rebuild of the same tag starts one run.

For a service that reports crashes through an error tracker instead, the tracker signs its own deliveries and cannot add that header, so a handler on your server receives the alert and forwards the traceback to the trigger. Keep the automation's runs per hour low: a container that restarts on every failure reports the same import error many times.

## Why run it on Rush?

Two errors stand between the pinned version and a running service, and the first hides the second until the environment changes. On a laptop with an old Tornado the service imports and the decorator looks fine. A Rush sandbox starts clean on a current Python, meets the 5.1.1 import failure, lifts the bound, meets the decorator error, and installs 5.1.1, 6.0.4 and 6.6 in turn to pin down where each was introduced, with each command kept in the record.

Rewriting a callback handler as a coroutine is where a quiet mistake costs a request that never finishes or finishes twice. A `tornado.testing` case that fetches the route through the real application is the check that a diff cannot give, and it runs in the sandbox against a stub for the slow work, so the pull request arrives with the response code and body the reviewer would otherwise have to reproduce.

## Frequently asked questions

### Which Tornado release removed @tornado.web.asynchronous?

Tornado 6.0, published 2019-03-01. Installed one at a time, 5.1.1 still has the attribute and 6.0.4 does not. A requirement with an upper bound of 6.0 never saw the change, which is why it appears years later, when that bound is lifted.

### Why did my pinned Tornado 5 stop importing before I upgraded anything?

On Python 3.11 Tornado 5.1.1 raises `AttributeError: module 'collections' has no attribute 'MutableMapping'` on import, inside its own code. The project's Dockerfile builds on Python 3.9, where it still imports. The pin breaks when the base image moves, and lifting it is what then exposes the removed decorator.

### Can I keep the thread pool and the callback style?

The thread pool stays; the callback goes. `run_in_executor` runs the same function on a `concurrent.futures` executor of the same size and returns something the handler can await, so the completion code runs after the await instead of in a callback. The handler still writes the same JSON and calls `finish` once.

### Which Tornado 6 can I upgrade to on Python 3.9?

6.5.2 is the newest that accepts Python 3.9; 6.6 requires 3.11. 6.4.2 accepts 3.8. The pull request names the range that fits the Dockerfile's base image, so the requirement change and the image stay consistent.

### Does the agent need the Bing or Bitly keys?

No. The handler is tested with a stub in place of the module manager, so no module runs. The tests in the repository that query live archives and search APIs are left for an environment that has the keys, and the pull request says which ones those are.

## More jobs like this: Fix a bug from an alert

- [Fix CryptographyDeprecationWarning: TripleDES Has Been Moved in a Paramiko Tool](https://getrush.ai/run/fix-tripledes-cryptography-deprecation-warning/paramiko/)
- [Fix "AttributeError: module 'tweepy' has no attribute 'StreamListener'"](https://getrush.ai/run/fix-tweepy-streamlistener-attribute-error/tweepy/)
- [Fix "AttributeError: type object 'Qt' has no attribute 'AlignCenter'" When Moving to PyQt6](https://getrush.ai/run/fix-type-object-qt-has-no-attribute-aligncenter/pyqt6/)
- [Fix "uninitialized constant Fixnum (NameError)" on Ruby 3.2 and later](https://getrush.ai/run/fix-uninitialized-constant-fixnum/ruby/)
- [Fix "AttributeError: 'TestCase' object has no attribute 'assertEquals'" on Python 3.12](https://getrush.ai/run/fix-unittest-assertequals-attribute-error/unittest/)
- [Fix "AttributeError: module 'unittest' has no attribute 'makeSuite'" on Python 3.13](https://getrush.ai/run/fix-unittest-makesuite-attribute-error/unittest/)

## Keep reading

- [How a Rush run works on your repository, from request to pull request](https://getrush.ai/cloud/)
- [Compare cloud agents, agent sandboxes and AI code review](https://getrush.ai/compare/)
- [Rush pricing: Free, Pro and Max](https://getrush.ai/pricing/)
