This repository was archived by the owner on Apr 26, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +16
-1
lines changed
Expand file tree Collapse file tree 3 files changed +16
-1
lines changed Original file line number Diff line number Diff line change 1+ The Synapse manhole no longer needs coroutines to be wrapped in `defer.ensureDeferred`.
Original file line number Diff line number Diff line change @@ -67,7 +67,7 @@ This gives a Python REPL in which `hs` gives access to the
6767` synapse.server.HomeServer` object - which in turn gives access to many other
6868parts of the process.
6969
70- Note that any call which returns a coroutine will need to be wrapped in `ensureDeferred`.
70+ Note that, prior to Synapse 1.41, any call which returns a coroutine will need to be wrapped in `ensureDeferred`.
7171
7272As a simple example, retrieving an event from the database :
7373
Original file line number Diff line number Diff line change 1212# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1313# See the License for the specific language governing permissions and
1414# limitations under the License.
15+ import inspect
1516import sys
1617import traceback
1718
2021from twisted .conch .manhole import ColoredManhole , ManholeInterpreter
2122from twisted .conch .ssh .keys import Key
2223from twisted .cred import checkers , portal
24+ from twisted .internet import defer
2325
2426PUBLIC_KEY = (
2527 "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDHhGATaW4KhE23+7nrH4jFx3yLq9OjaEs5"
@@ -141,3 +143,15 @@ def showtraceback(self):
141143 self .write ("" .join (lines ))
142144 finally :
143145 last_tb = ei = None
146+
147+ def displayhook (self , obj ):
148+ """
149+ We override the displayhook so that we automatically convert coroutines
150+ into Deferreds. (Our superclass' displayhook will take care of the rest,
151+ by displaying the Deferred if it's ready, or registering a callback
152+ if it's not).
153+ """
154+ if inspect .iscoroutine (obj ):
155+ super ().displayhook (defer .ensureDeferred (obj ))
156+ else :
157+ super ().displayhook (obj )
You can’t perform that action at this time.
0 commit comments