csail-csg / pyverilator

Python wrapper for verilator model
MIT License
78 stars 34 forks source link

Catch-all exception handlers break Ctrl+C #5

Open cpitclaudel opened 4 years ago

cpitclaudel commented 4 years ago

This block:

                try:
                    # try to call collection_set()
                    obj.collection_set(value)
                except:
                    raise TypeError("Item '%s' can not be set" % name)

and this one:

            try:
                obj.collection_set(value)
            except:
                raise TypeError("Item '%s' can not be set" % name)

cause issues with keyboard interrupts:

Traceback (most recent call last):
  File "/build/pyverilator/pyverilator/pyverilator.py", line 187, in __setattr__
    obj.collection_set(value)
  File "/build/pyverilator/pyverilator/pyverilator.py", line 326, in collection_set
    self.write(value)
  File "/build/pyverilator/pyverilator/pyverilator.py", line 323, in write
    self.write_function_and_args[0](*self.write_function_and_args[1:], value)
  File "/build/pyverilator/pyverilator/pyverilator.py", line 652, in _write_32
    self._post_write_hook(port_name, value)
  File "/build/pyverilator/pyverilator/pyverilator.py", line 670, in _post_write_hook
    self.eval()
  File "/build/pyverilator/pyverilator/pyverilator.py", line 707, in eval
    fn.argtypes = [ctypes.c_void_p]
KeyboardInterrupt

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "_objects/rv32.v/rvcore.pyverilator.py", line 125, in <module>
    main()
  File "_objects/rv32.v/rvcore.pyverilator.py", line 122, in main
    sim.run(args.ncycles)
  File "_objects/rv32.v/rvcore.pyverilator.py", line 88, in run
    self.tick()
  File "_objects/rv32.v/rvcore.pyverilator.py", line 49, in tick
    self.sim.io.CLK = 1
  File "/build/pyverilator/pyverilator/pyverilator.py", line 189, in __setattr__
    raise TypeError("Item '%s' can not be set" % name)
TypeError: Item 'CLK' can not be set

Could these except: be change to catch a specific error, instead of any exception? Maybe the Signal class should have a generic collection_get that throws an error that Input would override