Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IceCreamDebugger now ignores exceptions in formatting #152

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

NightMachinery
Copy link

@NightMachinery NightMachinery commented Aug 4, 2023

When using icecream with multiprocessing, I had this exception. So I simply added a try-catch-print to Icecream to avoid breaking the program when something unexpected happens, as the results of the print are for debugging purposes and don't change program behavior anyway.

This exception interrupted a longrunning computation, so I believe my PR is quite useful.

Traceback (most recent call last):                                                         
  File "/home/mehri/micromamba/envs/p310/lib/python3.10/multiprocessing/pool.py", line 125,
 in worker                                                                                 
    result = (True, func(*args, **kwds))                                                   
  File "/home/mehri/code/DecompV/decompv/x/ds/utils.py", line 2066, in pt_logits_to_cls_met
rics                                                                                       
  File "/home/mehri/code/DecompV/decompv/x/ds/utils.py", line 2044, in logits_to_cls_metric
s                                                                                          
    # ic(len(tds_masked_pred), len(tds_masked_pred.dataset), len(dataset_masked_logits))   
  File "/home/mehri/code/DecompV/decompv/x/ds/utils.py", line 2010, in compute_cls_metrics 
    ):                                                                                     
  File "/home/mehri/micromamba/envs/p310/lib/python3.10/site-packages/icecream/icecream.py"
, line 208, in __call__                                                           
    out = self._format(callFrame, *args)                                                   
  File "/home/mehri/micromamba/envs/p310/lib/python3.10/site-packages/icecream/icecream.py"
, line 242, in _format                                                                     
    out = self._formatArgs(                                                                
  File "/home/mehri/micromamba/envs/p310/lib/python3.10/site-packages/icecream/icecream.py"
, line 255, in _formatArgs                                                                 
    out = self._constructArgumentOutput(prefix, context, pairs)                            
  File "/home/mehri/micromamba/envs/p310/lib/python3.10/site-packages/icecream/icecream.py"
, line 304, in _constructArgumentOutput                                                    
    arg_lines = [                                                                          
  File "/home/mehri/micromamba/envs/p310/lib/python3.10/site-packages/icecream/icecream.py"
, line 305, in <listcomp>                                                                  
    format_pair('', arg, value)                                                            
  File "/home/mehri/micromamba/envs/p310/lib/python3.10/site-packages/icecream/icecream.py"
, line 146, in format_pair                                                                 
    arg_lines = indented_lines(prefix, arg)                                                
  File "/home/mehri/micromamba/envs/p310/lib/python3.10/site-packages/icecream/icecream.py"
, line 139, in indented_lines                                                              
    return [prefix + lines[0]] + [                                                         
IndexError: list index out of range   

@NightMachinery NightMachinery changed the title IceCreamDebugger ignores exceptions IceCreamDebugger now ignores exceptions in formatting Aug 4, 2023
@NightMachinery NightMachinery marked this pull request as ready for review August 4, 2023 09:34
@NightMachinery
Copy link
Author

@gruns Can you merge this in? I just had another run interrupted because I was editing the source code of my program (while the code was running) and icecream fails if it cannot parse the source code.

  File ~/micromamba/envs/p310/lib/python3.10/site-packages/icecream/icecream.py:208 in __call__
    out = self._format(callFrame, *args)

  File ~/micromamba/envs/p310/lib/python3.10/site-packages/icecream/icecream.py:242 in _format
    out = self._formatArgs(

  File ~/micromamba/envs/p310/lib/python3.10/site-packages/icecream/icecream.py:249 in _formatArgs
    sanitizedArgStrs = [

  File ~/micromamba/envs/p310/lib/python3.10/site-packages/icecream/icecream.py:250 in <listcomp>
    source.get_text_with_indentation(arg)

  File ~/micromamba/envs/p310/lib/python3.10/site-packages/icecream/icecream.py:120 in get_text_with_indentation
    result = self.asttokens().get_text(node)

  File ~/micromamba/envs/p310/lib/python3.10/site-packages/executing/executing.py:443 in asttokens
    self._asttokens = self.asttext().asttokens

  File ~/micromamba/envs/p310/lib/python3.10/site-packages/asttokens/asttokens.py:329 in asttokens
    tree=self.tree,

  File ~/micromamba/envs/p310/lib/python3.10/site-packages/asttokens/asttokens.py:319 in tree
    self._tree = ast.parse(self._text, self._filename)

  File ~/micromamba/envs/p310/lib/python3.10/ast.py:50 in parse
    return compile(source, filename, mode, flags,

  File ~/code/DecompV/decompv/x/ds/utils.py:2373
    else:
    ^
IndentationError: expected an indented block after 'elif' statement on line 2370

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant