spyder-ide / spyder

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

Marking all text at once freezes spyder for many seconds for larger codes with text #21680

Open Chuck321123 opened 8 months ago

Chuck321123 commented 8 months ago

Issue Report Checklist

Checklist checked

Problem Description

So I'm working on my code which is near 10000 lines with codes and text, but when i press CTRL + A to mark everything, everything freezes for up to a minute. This is before running the code.

What steps reproduce the problem?

Find a code that is over 10000 lines with both code and text in it. Hit CTRL + A. Could also create a 200 line code with text and copy paste it up to 10000 lines.

Made a fictive code from chatGPT where the problem also occurs if you copy paste it enough:

import pandas as pd
import numpy as np

# Create a DataFrame with random data
np.random.seed(42)
data = {
    'Name': [f'Person {i}' for i in range(1, 11)],
    'Age': np.random.randint(20, 40, 10),
    'Salary': np.random.randint(50000, 80000, 10),
    'Department': np.random.choice(['HR', 'IT', 'Finance'], 10)
}

df = pd.DataFrame(data)

# Display the original DataFrame
print("Original DataFrame:")
print(df)

# Add a new column 'Bonus' based on a condition
df['Bonus'] = np.where(df['Salary'] > 60000, 0.1 * df['Salary'], 0)

# Calculate the average age and salary per department
department_stats = df.groupby('Department').agg({'Age': 'mean', 'Salary': 'mean'}).reset_index()
department_stats.columns = ['Department', 'AvgAge', 'AvgSalary']

# Merge the original DataFrame with department statistics
df = pd.merge(df, department_stats, on='Department')

# Create a new column 'SalaryIncrease' based on the difference from the average salary
df['SalaryIncrease'] = df['Salary'] - df['AvgSalary']

# Filter out individuals with age less than the department's average age
df = df[df['Age'] > df['AvgAge']]

# Display the final DataFrame
print("\nDataFrame after manipulation:")
print(df)

What is the expected output?

That it doesnt freeze until i run the code

Versions

Dependencies

# Mandatory:
atomicwrites >=1.2.0             :  1.4.1 (OK)
chardet >=2.0.0                  :  5.2.0 (OK)
cloudpickle >=0.5.0              :  3.0.0 (OK)
cookiecutter >=1.6.0             :  2.5.0 (OK)
diff_match_patch >=20181111      :  20230430 (OK)
intervaltree >=3.0.2             :  3.1.0 (OK)
IPython >=8.13.0,<9.0.0,!=8.17.1 :  8.19.0 (OK)
jedi >=0.17.2,<0.20.0            :  0.19.1 (OK)
jellyfish >=0.7                  :  1.0.3 (OK)
jsonschema >=3.2.0               :  4.20.0 (OK)
keyring >=17.0.0                 :  24.3.0 (OK)
nbconvert >=4.0                  :  7.13.1 (OK)
numpydoc >=0.6.0                 :  1.6.0 (OK)
paramiko >=2.4.0                 :  3.4.0 (OK)
parso >=0.7.0,<0.9.0             :  0.8.3 (OK)
pexpect >=4.4.0                  :  4.9.0 (OK)
pickleshare >=0.4                :  0.7.5 (OK)
psutil >=5.3                     :  5.9.7 (OK)
pygments >=2.0                   :  2.17.2 (OK)
pylint >=2.5.0,<3.1              :  3.0.3 (OK)
pylint_venv >=3.0.2              :  3.0.3 (OK)
pyls_spyder >=0.4.0              :  0.4.0 (OK)
pylsp >=1.9.0,<1.10.0            :  1.9.0 (OK)
pylsp_black >=1.2.0,<3.0.0       :  2.0.0 (OK)
qdarkstyle >=3.2.0,<3.3.0        :  3.2.3 (OK)
qstylizer >=0.2.2                :  0.2.2 (OK)
qtawesome >=1.2.1                :  1.3.0 (OK)
qtconsole >=5.5.0,<5.6.0         :  5.5.1 (OK)
qtpy >=2.1.0                     :  2.4.1 (OK)
rtree >=0.9.7                    :  1.1.0 (OK)
setuptools >=49.6.0              :  68.2.2 (OK)
sphinx >=0.6.6                   :  7.2.6 (OK)
spyder_kernels >=2.5.0,<2.6.0    :  2.5.0 (OK)
textdistance >=4.2.0             :  4.6.1 (OK)
three_merge >=0.1.1              :  0.1.1 (OK)
watchdog >=0.10.3                :  3.0.0 (OK)
zmq >=22.1.0                     :  25.1.2 (OK)

# Optional:
cython >=0.21                    :  None (NOK)
matplotlib >=3.0.0               :  3.8.2 (OK)
numpy >=1.7                      :  1.26.2 (OK)
pandas >=1.1.1                   :  2.1.4 (OK)
scipy >=0.17.0                   :  1.11.4 (OK)
sympy >=0.7.3                    :  None (NOK)
ccordoba12 commented 8 months ago

Hey @Chuck321123, thanks for reporting. I can't reproduce this on Linux and I don't see that we're doing anything especial about the select all operation.

@dalthviz, could you try it on Windows?

Chuck321123 commented 8 months ago

@ccordoba12 So this is a weird bug. Created a new env in Windows and clean installed Spyder and reset its settings. Everything went smooth, but then i zoomed out the code and hit Ctrl + A and then it crashed/froze again. Tried the exact same thing in Ubuntu on my Raspberry Pi but i couldnt replicate it there.

Update: Found the solution where i disabled "Highlight occurence after 1500ms" under Editor in Preferences and Spyder doesnt freeze anymore. My pc is not the newest but might be an idea to check into this

GitKia1392 commented 8 months ago

@dalthviz, could you try it on Windows

So @Chuck321123 , you could use the Windows 10+ installer with WineHQ I suppose u use Ubuntu but if you use like Linux mint you can try Ubuntu 22.04

(Jammy Jellyfish)

Linux Mint 21.x

Try this link: wiki.winehq.org/Ubuntu

Should work regards

dalthviz commented 8 months ago

I think I was able to reproduce the crash/freeze. Something that I noticed is that at some point seems like the scrollflags for the occurence highlighting disappear/are still not set and if I try to do Ctrl + A multiple times while then quickly start clicking the Editor with the mouse Spyder freezes for some time. If in that state you keep trying to interact with Spyder it crashes. If you wait sometime it recovers:

image

Also, maybe the freeze could also be caused/easy to trigger when doing a mouse click while also still holding the Ctrl key, since sometimes after the freeze I got a new file open like if I did a Ctrl+ Right Mouse Click to trigger the Go to definition action :thinking:

freeze