diff options
author | reivilibre <38398653+reivilibre@users.noreply.github.com> | 2021-08-16 18:11:48 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-08-16 18:11:48 +0100 |
commit | 19e51b14d23f756883688fd8238da61c6ff29cc3 (patch) | |
tree | 2eae0757631271a415460dba5f3aa3994dd81abe /synapse/util/manhole.py | |
parent | Update CONTRIBUTING.md to fix index links and SyTest instructions (#10599) (diff) | |
download | synapse-19e51b14d23f756883688fd8238da61c6ff29cc3.tar.xz |
Manhole: wrap coroutines in `defer.ensureDeferred` automatically (#10602)
Diffstat (limited to '')
-rw-r--r-- | synapse/util/manhole.py | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/synapse/util/manhole.py b/synapse/util/manhole.py index da24ba0470..522daa323d 100644 --- a/synapse/util/manhole.py +++ b/synapse/util/manhole.py @@ -12,6 +12,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. +import inspect import sys import traceback @@ -20,6 +21,7 @@ from twisted.conch.insults import insults from twisted.conch.manhole import ColoredManhole, ManholeInterpreter from twisted.conch.ssh.keys import Key from twisted.cred import checkers, portal +from twisted.internet import defer PUBLIC_KEY = ( "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDHhGATaW4KhE23+7nrH4jFx3yLq9OjaEs5" @@ -141,3 +143,15 @@ class SynapseManholeInterpreter(ManholeInterpreter): self.write("".join(lines)) finally: last_tb = ei = None + + def displayhook(self, obj): + """ + We override the displayhook so that we automatically convert coroutines + into Deferreds. (Our superclass' displayhook will take care of the rest, + by displaying the Deferred if it's ready, or registering a callback + if it's not). + """ + if inspect.iscoroutine(obj): + super().displayhook(defer.ensureDeferred(obj)) + else: + super().displayhook(obj) |