@@ -291,7 +291,12 @@ def effective_deadline(self):
291291 return min (self ._scope .deadline , self ._parent .effective_deadline ())
292292
293293
294- MISNESTING_ADVICE = """Typically this is caused by one of the following:
294+ MISNESTING_ADVICE = """
295+ This is probably a bug in your code, that has caused Trio's internal state to
296+ become corrupted. We'll do our best to recover, but from now on there are
297+ no guarantees.
298+
299+ Typically this is caused by one of the following:
295300 - yielding within a generator or async generator that's opened a cancel
296301 scope or nursery (unless the generator is a @contextmanager or
297302 @asynccontextmanager); see https://github.com/python-trio/trio/issues/638
@@ -409,7 +414,7 @@ def _close(self, exc):
409414 # without changing any state.
410415 new_exc = RuntimeError (
411416 "Cancel scope stack corrupted: attempted to exit {!r} "
412- "from unrelated {!r}\n \n {}" .format (
417+ "from unrelated {!r}\n {}" .format (
413418 self , scope_task , MISNESTING_ADVICE
414419 )
415420 )
@@ -423,7 +428,7 @@ def _close(self, exc):
423428 # pass silently.
424429 new_exc = RuntimeError (
425430 "Cancel scope stack corrupted: attempted to exit {!r} "
426- "in {!r} that's still within its child {!r}\n \n {}" .format (
431+ "in {!r} that's still within its child {!r}\n {}" .format (
427432 self , scope_task , scope_task ._cancel_status ._scope ,
428433 MISNESTING_ADVICE
429434 )
@@ -1281,7 +1286,7 @@ def task_exited(self, task, outcome):
12811286 # traceback frame included
12821287 raise RuntimeError (
12831288 "Cancel scope stack corrupted: cancel scope surrounding "
1284- "{!r} was closed before the task exited\n \n {}" .format (
1289+ "{!r} was closed before the task exited\n {}" .format (
12851290 task , MISNESTING_ADVICE
12861291 )
12871292 )
0 commit comments