Search code examples
pythonstatic-methodsstack-traceclass-method

statcktrace of classmethod not getting printed in python


There is a @classmethod in a class which is being called automatically when class is imported. I want to know the parameters being passed to that method. So I deliberately added a code to crash that function and to print the stacktrace. However, it is not printing who is calling this load method.

I actually want to know who is sending values of parameters (Specifically cuda_device)

 @classmethod
    def load(cls,
             config: Params,
             serialization_dir: str,
             weights_file: str = None,
             cuda_device: int = -1) -> 'Model':

        who called me?   #line added by me to crash and print stacktrace
  File "/data/TFS/AI%20-%20Projects/MULTI_PROC/allen_ws/urls.py", line 19, in <module>
    from allen_ws import ANLP_API_SB1
  File "/data/TFS/AI%20-%20Projects/MULTI_PROC/allen_ws/ANLP_API_SB1.py", line 5, in <module>
    from allennlp.predictors.predictor import Predictor
  File "/anaconda3/envs/allennlpenv/lib/python3.6/site-packages/allennlp/predictors/__init__.py", line 9, in <module>
    from allennlp.predictors.predictor import Predictor
  File "/anaconda3/envs/allennlpenv/lib/python3.6/site-packages/allennlp/predictors/predictor.py", line 8, in <module>
    from allennlp.models import Model
  File "/anaconda3/envs/allennlpenv/lib/python3.6/site-packages/allennlp/models/__init__.py", line 6, in <module>
    from allennlp.models.model import Model
  File "/anaconda3/envs/allennlpenv/lib/python3.6/site-packages/allennlp/models/model.py", line 331
    who called me?

In above stack trace models/__ init __ .py is calling the model.py line 331 (at line 331 I added "who called me"), the content of models/__ init __ .py at line 6 following is written:

from allennlp.models.model import Model

This is also not calling _load method with any parameters.
Suggestions please, how can I find who is passing cuda_device parameter value to load function?


Solution

  • You have introduced a syntax error into your code. That means your class cannot be imported, let alone run.

    If you want to see a runtime stack trace then introduce a runtime error, not a syntax error.

    a = 1 / 0
    

    should do it.