spyder-ide / spyder

Official repository for Spyder - The Scientific Python Development Environment
https://www.spyder-ide.org
MIT License
8.33k stars 1.61k forks source link

Windows fatal exception: access violation. Spyder debugger crashing after some time. #20909

Open abhishek7997 opened 1 year ago

abhishek7997 commented 1 year ago

Description

Debugging a python program in spyder IDE using pdb. pdb crashes with the following error:- Windows fatal exception: access violation

What steps will reproduce the problem?

No idea. I am just setting breakpoints in my main file and in another file which is imported in the main file. pdb crashes with the error:- Windows fatal exception: access violation

Traceback

Traceback (most recent call last):
  File "C:\Users\user\miniconda3\envs\spyder-env\Lib\site-packages\spyder\plugins\ipythonconsole\comms\kernelcomm.py", line 123, in comm_channel_manager
    yield
  File "C:\Users\user\miniconda3\envs\spyder-env\Lib\site-packages\spyder\plugins\ipythonconsole\comms\kernelcomm.py", line 224, in _get_call_return_value
    return super(KernelComm, self)._get_call_return_value(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\user\miniconda3\envs\spyder-env\Lib\site-packages\spyder_kernels\comms\commbase.py", line 435, in _get_call_return_value
    self._wait_reply(call_id, call_name, timeout)
  File "C:\Users\user\miniconda3\envs\spyder-env\Lib\site-packages\spyder\plugins\ipythonconsole\comms\kernelcomm.py", line 246, in _wait_reply
    self._wait(got_reply, self._sig_got_reply, timeout_msg, timeout)
  File "C:\Users\user\miniconda3\envs\spyder-env\Lib\site-packages\spyder\plugins\ipythonconsole\comms\kernelcomm.py", line 283, in _wait
    raise TimeoutError(timeout_msg)
TimeoutError: Timeout while waiting for {'5d4e59f99bda421592ff6764cb58ed20': (False, <bound method ShellWidget.on_getting_cwd of <spyder.plugins.ipythonconsole.widgets.shell.ShellWidget object at 0x000001CE567B4430>>), '1decff41b3714e3683ff9e5c72f800cc': (False, <bound method ShellWidget.on_getting_cwd of <spyder.plugins.ipythonconsole.widgets.shell.ShellWidget object at 0x000001CE567B4430>>), '59b283de56404855bc7d19875fa5991a': (False, <bound method ShellWidget.on_getting_cwd of <spyder.plugins.ipythonconsole.widgets.shell.ShellWidget object at 0x000001CE567B4430>>), '200e95953e57498fa970a1d678222b94': (False, <bound method ShellWidget.on_getting_cwd of <spyder.plugins.ipythonconsole.widgets.shell.ShellWidget object at 0x000001CE567B4430>>), '4c09f818764244d6a74d9442d3c8df40': (False, <bound method ShellWidget.on_getting_cwd of <spyder.plugins.ipythonconsole.widgets.shell.ShellWidget object at 0x000001CE567B4430>>), '8b723d9f2ee74b79905883b69fb8aa5d': (False, <bound method ShellWidget.on_getting_cwd of <spyder.plugins.ipythonconsole.widgets.shell.ShellWidget object at 0x000001CE567B4430>>), 'cfe8daf418dc4c0eafd5c8791aab6f7c': (True, None)}

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\user\miniconda3\envs\spyder-env\Lib\site-packages\spyder\plugins\help\plugin.py", line 331, in set_object_text
    self.get_widget().set_object_text(
  File "C:\Users\user\miniconda3\envs\spyder-env\Lib\site-packages\spyder\plugins\help\widgets.py", line 936, in set_object_text
    found = self.show_help(text, ignore_unknown=ignore_unknown)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\user\miniconda3\envs\spyder-env\Lib\site-packages\spyder\plugins\help\widgets.py", line 1049, in show_help
    if not shell.is_defined(obj_text):
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\user\miniconda3\envs\spyder-env\Lib\site-packages\spyder\plugins\ipythonconsole\widgets\help.py", line 133, in is_defined
    ).is_defined(objtxt, force_import=force_import)
      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\user\miniconda3\envs\spyder-env\Lib\site-packages\spyder_kernels\comms\commbase.py", line 557, in __call__
    return self._comms_wrapper._get_call_return_value(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\user\miniconda3\envs\spyder-env\Lib\site-packages\spyder\plugins\ipythonconsole\comms\kernelcomm.py", line 222, in _get_call_return_value
    with self.comm_channel_manager(
  File "C:\Users\user\miniconda3\envs\spyder-env\Lib\contextlib.py", line 155, in __exit__
    self.gen.throw(typ, value, traceback)
  File "C:\Users\user\miniconda3\envs\spyder-env\Lib\site-packages\spyder\plugins\ipythonconsole\comms\kernelcomm.py", line 127, in comm_channel_manager
    self._comms[comm_id]['comm']._send_channel = (
    ~~~~~~~~~~~^^^^^^^^^
KeyError: '54b0ce53efab11eda86f8cb88d2b7eff'

Another error

Windows fatal exception: access violation

Main thread:
Current thread 0x00001f5c (most recent call first):
  File "C:\Users\user\miniconda3\envs\citation_sentiment_analysis_env\Lib\site-packages\regex\regex.py", line 676 in _compile
  File "C:\Users\user\miniconda3\envs\citation_sentiment_analysis_env\Lib\site-packages\regex\regex.py", line 353 in compile
  File "C:\Users\user\miniconda3\envs\citation_sentiment_analysis_env\Lib\site-packages\nltk\tokenize\casual.py", line 215 in <module>
  File "<frozen importlib._bootstrap>", line 241 in _call_with_frames_removed
  File "<frozen importlib._bootstrap_external>", line 940 in exec_module
  File "<frozen importlib._bootstrap>", line 690 in _load_unlocked
  File "<frozen importlib._bootstrap>", line 1149 in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 1178 in _find_and_load
  File "C:\Users\user\miniconda3\envs\citation_sentiment_analysis_env\Lib\site-packages\nltk\tokenize\__init__.py", line 65 in <module>
  File "<frozen importlib._bootstrap>", line 241 in _call_with_frames_removed
  File "<frozen importlib._bootstrap_external>", line 940 in exec_module
  File "<frozen importlib._bootstrap>", line 690 in _load_unlocked
  File "<frozen importlib._bootstrap>", line 1149 in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 1178 in _find_and_load
  File "C:\Users\user\miniconda3\envs\citation_sentiment_analysis_env\Lib\site-packages\nltk\text.py", line 29 in <module>
  File "<frozen importlib._bootstrap>", line 241 in _call_with_frames_removed
  File "<frozen importlib._bootstrap_external>", line 940 in exec_module
  File "<frozen importlib._bootstrap>", line 690 in _load_unlocked
  File "<frozen importlib._bootstrap>", line 1149 in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 1178 in _find_and_load
  File "C:\Users\user\miniconda3\envs\citation_sentiment_analysis_env\Lib\site-packages\nltk\__init__.py", line 138 in <module>
  File "<frozen importlib._bootstrap>", line 241 in _call_with_frames_removed
  File "<frozen importlib._bootstrap_external>", line 940 in exec_module
  File "<frozen importlib._bootstrap>", line 690 in _load_unlocked
  File "<frozen importlib._bootstrap>", line 1149 in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 1178 in _find_and_load
  File "D:\Dev\MachineLearning\Projects\Citation_Text_Extractor\constants.py", line 10 in <module>
  File "<frozen importlib._bootstrap>", line 241 in _call_with_frames_removed
  File "<frozen importlib._bootstrap_external>", line 940 in exec_module
  File "<frozen importlib._bootstrap>", line 690 in _load_unlocked
  File "<frozen importlib._bootstrap>", line 1149 in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 1178 in _find_and_load
  File "d:\dev\machinelearning\projects\citation_text_extractor\citations_text_extractor.py", line 8 in <module>
  File "C:\Users\user\miniconda3\envs\citation_sentiment_analysis_env\Lib\bdb.py", line 597 in run
  File "C:\Users\user\miniconda3\envs\citation_sentiment_analysis_env\Lib\site-packages\spyder_kernels\customize\spyderpdb.py", line 889 in run
  File "C:\Users\user\miniconda3\envs\citation_sentiment_analysis_env\Lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 473 in exec_code
  File "C:\Users\user\miniconda3\envs\citation_sentiment_analysis_env\Lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 615 in _exec_file
  File "C:\Users\user\miniconda3\envs\citation_sentiment_analysis_env\Lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 660 in debugfile
  File "C:\Users\user\AppData\Local\Temp\ipykernel_15556\49145703.py", line 1 in <module>Windows fatal exception: access violation

Main thread:
Current thread 0x00001f5c (most recent call first):
  File "C:\Users\user\miniconda3\envs\citation_sentiment_analysis_env\Lib\site-packages\regex\regex.py", line 676 in _compile
  File "C:\Users\user\miniconda3\envs\citation_sentiment_analysis_env\Lib\site-packages\regex\regex.py", line 353 in compile
  File "C:\Users\user\miniconda3\envs\citation_sentiment_analysis_env\Lib\site-packages\nltk\tokenize\casual.py", line 215 in <module>
  File "<frozen importlib._bootstrap>", line 241 in _call_with_frames_removed
  File "<frozen importlib._bootstrap_external>", line 940 in exec_module
  File "<frozen importlib._bootstrap>", line 690 in _load_unlocked
  File "<frozen importlib._bootstrap>", line 1149 in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 1178 in _find_and_load
  File "C:\Users\user\miniconda3\envs\citation_sentiment_analysis_env\Lib\site-packages\nltk\tokenize\__init__.py", line 65 in <module>
  File "<frozen importlib._bootstrap>", line 241 in _call_with_frames_removed
  File "<frozen importlib._bootstrap_external>", line 940 in exec_module
  File "<frozen importlib._bootstrap>", line 690 in _load_unlocked
  File "<frozen importlib._bootstrap>", line 1149 in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 1178 in _find_and_load
  File "C:\Users\user\miniconda3\envs\citation_sentiment_analysis_env\Lib\site-packages\nltk\text.py", line 29 in <module>
  File "<frozen importlib._bootstrap>", line 241 in _call_with_frames_removed
  File "<frozen importlib._bootstrap_external>", line 940 in exec_module
  File "<frozen importlib._bootstrap>", line 690 in _load_unlocked
  File "<frozen importlib._bootstrap>", line 1149 in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 1178 in _find_and_load
  File "C:\Users\user\miniconda3\envs\citation_sentiment_analysis_env\Lib\site-packages\nltk\__init__.py", line 138 in <module>
  File "<frozen importlib._bootstrap>", line 241 in _call_with_frames_removed
  File "<frozen importlib._bootstrap_external>", line 940 in exec_module
  File "<frozen importlib._bootstrap>", line 690 in _load_unlocked
  File "<frozen importlib._bootstrap>", line 1149 in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 1178 in _find_and_load
  File "D:\Dev\MachineLearning\Projects\Citation_Text_Extractor\constants.py", line 10 in <module>
  File "<frozen importlib._bootstrap>", line 241 in _call_with_frames_removed
  File "<frozen importlib._bootstrap_external>", line 940 in exec_module
  File "<frozen importlib._bootstrap>", line 690 in _load_unlocked
  File "<frozen importlib._bootstrap>", line 1149 in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 1178 in _find_and_load
  File "d:\dev\machinelearning\projects\citation_text_extractor\citations_text_extractor.py", line 8 in <module>
  File "C:\Users\user\miniconda3\envs\citation_sentiment_analysis_env\Lib\bdb.py", line 597 in run
  File "C:\Users\user\miniconda3\envs\citation_sentiment_analysis_env\Lib\site-packages\spyder_kernels\customize\spyderpdb.py", line 889 in run
  File "C:\Users\user\miniconda3\envs\citation_sentiment_analysis_env\Lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 473 in exec_code
  File "C:\Users\user\miniconda3\envs\citation_sentiment_analysis_env\Lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 615 in _exec_file
  File "C:\Users\user\miniconda3\envs\citation_sentiment_analysis_env\Lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 660 in debugfile
  File "C:\Users\user\AppData\Local\Temp\ipykernel_15556\49145703.py", line 1 in <module>

Versions

Dependencies

# Mandatory:
atomicwrites >=1.2.0                             :  1.4.1 (OK)
chardet >=2.0.0                                  :  5.1.0 (OK)
cloudpickle >=0.5.0                              :  2.2.1 (OK)
cookiecutter >=1.6.0                             :  2.1.1 (OK)
diff_match_patch >=20181111                      :  20200713 (OK)
intervaltree >=3.0.2                             :  3.0.2 (OK)
IPython >=7.31.1,<9.0.0,!=8.8.0,!=8.9.0,!=8.10.0 :  8.13.2 (OK)
jedi >=0.17.2,<0.19.0                            :  0.18.2 (OK)
jellyfish >=0.7                                  :  0.9.0 (OK)
jsonschema >=3.2.0                               :  4.17.3 (OK)
keyring >=17.0.0                                 :  23.13.1 (OK)
nbconvert >=4.0                                  :  7.2.9 (OK)
numpydoc >=0.6.0                                 :  1.5.0 (OK)
paramiko >=2.4.0                                 :  3.0.0 (OK)
parso >=0.7.0,<0.9.0                             :  0.8.3 (OK)
pexpect >=4.4.0                                  :  4.8.0 (OK)
pickleshare >=0.4                                :  0.7.5 (OK)
psutil >=5.3                                     :  5.9.4 (OK)
pygments >=2.0                                   :  2.14.0 (OK)
pylint >=2.5.0,<3.0                              :  2.16.1 (OK)
pylint_venv >=2.1.1                              :  2.3.0 (OK)
pyls_spyder >=0.4.0                              :  0.4.0 (OK)
pylsp >=1.7.2,<1.8.0                             :  1.7.2 (OK)
pylsp_black >=1.2.0                              :  1.2.1 (OK)
qdarkstyle >=3.0.2,<3.2.0                        :  3.0.3 (OK)
qstylizer >=0.2.2                                :  0.2.2 (OK)
qtawesome >=1.2.1                                :  1.2.2 (OK)
qtconsole >=5.4.2,<5.5.0                         :  5.4.3 (OK)
qtpy >=2.1.0                                     :  2.3.0 (OK)
rtree >=0.9.7                                    :  1.0.1 (OK)
setuptools >=49.6.0                              :  67.1.0 (OK)
sphinx >=0.6.6                                   :  6.1.3 (OK)
spyder_kernels >=2.4.3,<2.5.0                    :  2.4.3 (OK)
textdistance >=4.2.0                             :  4.5.0 (OK)
three_merge >=0.1.1                              :  0.1.1 (OK)
watchdog >=0.10.3                                :  2.2.1 (OK)
zmq >=22.1.0                                     :  25.0.0 (OK)

# Optional:
cython >=0.21                                    :  0.29.33 (OK)
matplotlib >=3.0.0                               :  3.6.3 (OK)
numpy >=1.7                                      :  1.24.2 (OK)
pandas >=1.1.1                                   :  1.5.3 (OK)
scipy >=0.17.0                                   :  1.10.0 (OK)
sympy >=0.7.3                                    :  1.11.1 (OK)
dalthviz commented 1 year ago

Hi @abhishek7997 thank you for the feedback! I'm not totally sure what could be happening here 🤔 Could it be possible for you to provide some example code to try to reproduce this is our side?

Pinging @ccordoba12 and @impact27 (maybe they could have some ideas how to further debug this)

Any other info in order to be able to reproduce this is greatly appreticated. Let us know!

abhishek7997 commented 1 year ago

Hi @abhishek7997 thank you for the feedback! I'm not totally sure what could be happening here 🤔 Could it be possible for you to provide some example code to try to reproduce this is our side?

Pinging @ccordoba12 and @impact27 (maybe they could have some ideas how to further debug this)

Any other info in order to be able to reproduce this is greatly appreticated. Let us know!

In my case, here is the code setup that I work with. The debugger first freezes, then crashes. Also, I don't think it is specific to this code. I have used a different environment in spyder (used miniconda to create new environment).

main.py:

from constants import CONSTANTS
from file_utils import FileUtils

ITEMS= {
   'text0': "./papers/research-paper.pdf"
}

for text in ITEMS.values():
    pages = FileUtils.extract_paragraphs(currentText) # <- I have added breakpoint here
    # rest of the code

utils.py:

import re
from io import StringIO

from pdfminer.high_level import extract_text
from pdfminer.converter import TextConverter
from pdfminer.layout import LAParams
from pdfminer.pdfdocument import PDFDocument
from pdfminer.pdfinterp import PDFResourceManager, PDFPageInterpreter
from pdfminer.pdfpage import PDFPage
from pdfminer.pdfparser import PDFParser
from pdfminer.high_level import extract_pages
from pdfminer.layout import LTTextContainer, LTTextBox

from text_utils import TextUtils

from typing import List

class FileUtils:
    @classmethod
    def extract_paragraphs(cls, file_name: str):
        paragraphs = []
        with open(file_name, 'rb') as file:
            resource_manager = PDFResourceManager()
            output_stream = StringIO()
            codec = 'utf-8'
            laparams = LAParams()
            converter = TextConverter(resource_manager, output_stream, codec=codec, laparams=laparams)
            interpreter = PDFPageInterpreter(resource_manager, converter)

            for page in PDFPage.get_pages(file, check_extractable=True):
                  interpreter.process_page(page)
                  extracted_text = output_stream.getvalue()

                  # Sanitize the extracted text
                  sanitized_text = re.sub(r'[\x00-\x08\x0b\x0c\x0e-\x1f\x7f-\x9f]', ' ', extracted_text)
                  print(sanitized_text) # <- I have added breakpoint here

                  paragraphs.extend(sanitized_text.splitlines())
                  output_stream.truncate(0)
                  output_stream.seek(0)

            converter.close()
            output_stream.close()

        return paragraphs

Spyder settings

image image

ccordoba12 commented 1 year ago

@abhishek7997, unfortunately your code is not reproducible because it depends on PDFResourceManager, LAParams, etc, which are not imported from anywhere in your utils.py module.

abhishek7997 commented 1 year ago

I removed the import statements before. The library I am using is pdfminer.six Here are the import statements of file_utils.py:-

import re from io import StringIO

from pdfminer.high_level import extract_text from pdfminer.converter import TextConverter from pdfminer.layout import LAParams from pdfminer.pdfdocument import PDFDocument from pdfminer.pdfinterp import PDFResourceManager, PDFPageInterpreter from pdfminer.pdfpage import PDFPage from pdfminer.pdfparser import PDFParser from pdfminer.high_level import extract_pages from pdfminer.layout import LTTextContainer, LTTextBox

from text_utils import TextUtils

from typing import List