#2826 closed task (fixed)

CLI: allow dispatch functions to return a Deferred

Reported by: warner Owned by: warner
Priority: normal Milestone: 1.12.0
Component: code Version: 1.11.0
Keywords: Cc:
Launchpad Bug:

Description

This will enable #2490 to run (async) Tor operations during tahoe create-node --listen=tor. Currently all CLI dispatch functions must finish synchronously.

The file-operation subcommands, which use blocking httplib calls, must be run from unit tests under deferToThread. #2825 is about fixing that, but this ticket will do some cleanup that will help. Specifically it will move the deferToThread down into runner.py, using the thread only on the subcommands which really need it. After this is fixed, there should be no deferToThread calls in the unit tests.

Change History (2)

comment:1 Changed at 2016-09-09T23:30:00Z by warner

The branch is ready to land. It looks like there's one deferToThread left in the test suite: test_runner.RunBinTahoeMixin.run_bintahoe uses subprocess.Popen underneath deferToThread. I *think* this can be replaced with a reactor.spawnProcess, but I'm not 100% sure, and I don't want to go messing with it right now, so I'm going to leave that cleanup for another day.

comment:2 Changed at 2016-09-09T23:30:26Z by Brian Warner <warner@…>

  • Resolution set to fixed
  • Status changed from new to closed

In 802cfc8/trunk:

CLI: allow dispatch functions to return Deferred

In addition, CLI functions are allowed to use sys.exit() instead of
always needing to return the exit code as an integer.

runner.py now knows about the blocking httplib calls in scripts/cli and
scripts/magic_folder, and uses deferToThread() to invoke them. Those
functions cannot return a Deferred: when rewrite them to use twisted.web
or treq, we'll remove this deferToThread call.

Option parsing was split out to a separate function for testing. We now
use twisted.internet.task.react() to start the reactor, which required
changing the way runner.py is tested.

closes ticket:2826

Note: See TracTickets for help on using tickets.