sim._pycoro: make src_loc() more robust.
authorwhitequark <whitequark@whitequark.org>
Thu, 27 Aug 2020 07:11:14 +0000 (07:11 +0000)
committerwhitequark <whitequark@whitequark.org>
Thu, 27 Aug 2020 07:11:14 +0000 (07:11 +0000)
  * Guard for finished coroutines.
  * Guard for coroutines yielding from iterators and not generators.

nmigen/sim/_pycoro.py

index 0421d57bce671cafb0a60b546f7bb09cc14b71e0..dbd7601d73d176996276dee8530fce8608d42e04 100644 (file)
@@ -32,7 +32,9 @@ class PyCoroProcess(Process):
 
     def src_loc(self):
         coroutine = self.coroutine
-        while coroutine.gi_yieldfrom is not None:
+        if coroutine is None:
+            return None
+        while coroutine.gi_yieldfrom is not None and inspect.isgenerator(coroutine.gi_yieldfrom):
             coroutine = coroutine.gi_yieldfrom
         if inspect.isgenerator(coroutine):
             frame = coroutine.gi_frame