jxmorris12 / language_tool_python

a free python grammar checker 📝✅
GNU General Public License v3.0
434 stars 64 forks source link

spell checker displays output then gets stuck in IDLE #56

Open gaurav-95 opened 2 years ago

gaurav-95 commented 2 years ago

This is my code, I am adding bullets wherever there is a new line and then trying to get spell-checked texts stored in res

import language_tool_python
#tool = language_tool_python.LanguageTool('en-US', config={ 'cacheSize': 1000, 'pipelineCaching': True })

text = 'A sentence with a error in the Hitchhiker’s Guide tot he Galaxy\n. Bet there is something here.\n Bests goats are in town.'
lines = text.split('\n\n' or '\n')
lines = [ "• " + para for para in lines]
res = "\n\n".join(lines)
with language_tool_python.LanguageTool('en-US', config={ 'cacheSize': 1000, 'pipelineCaching': True }) as tool:
  # do stuff with `tool`
    result = tool.correct(res)
    print(result)

I get an output of the corrected text. But there is no error, no other output. Just freezes there. I tried giving explicit close and using with statement as well to no avail.

jxmorris12 commented 2 years ago

Thanks for reporting @gaurav-95. So to be clear, the print(result) line actually prints? But then the closing of the with statement hangs?

jxmorris12 commented 2 years ago

@gaurav-95 I just tried running this on my machine and it runs fine - result is printed, and nothing freezes. Please reopen if you're still having issues.

gaurav-95 commented 2 years ago

Will check again and post output.

gaurav-95 commented 2 years ago

Yes, i can confirm that the output gets printed but the code keeps running on the terminal. It does not finish/ exit from runtime.

image

jxmorris12 commented 2 years ago

I think we can diagnose this issue as: self._terminate_server() not killing server on Windows. That's the most likely cause.

It's difficult for me to debug without a windows machine...

gaurav-95 commented 2 years ago

I see, my bad to not mention I was running on windows beforehand.

Pikamander2 commented 2 years ago

@jxmorris12 - I'm not getting any hard freezes on Windows 10, but I do have a likely-related problem where the java.exe process never ends even after IDLE is closed.

image

At one point I ended up with 20+ java.exe processes running hours after I had finished what I was doing.

Also, each Java process that's running seems to make the script's startup slower. It flashes a window briefly at the bottom of Windows one time for every current process, so if you have 10 java.exe processes running then it'll flash 10 times before the language tool object is successfully created.

Here's the only code required to reproduce the issue:

tool = language_tool_python.LanguageTool('en-US')
jxmorris12 commented 2 years ago

@Pikamander2 thanks for reporting, this is a serious issue. Are you running that code in a script? Or through the python IDLE?

Pikamander2 commented 2 years ago

@jxmorris12 - I just tested out the process bug in both CMD and IDLE and it looks like this bug also only occurs with IDLE.

In regards to Windows testing, one option that you could try is to run an evaluation copy of Windows in a virtual machine. Alternatively, a Windows VPS is about $5 per month.

jxmorris12 commented 2 years ago

This SO answer looks relevant: https://stackoverflow.com/a/55411153/2287177

bMorgan01 commented 2 years ago

Sorry for reviving this, I might have some info that can help.

I see this hanging issue upon calling tool.close() in WSL and in the pydev debugger on top of the previously mentioned terminals.

Weird that this works on my linux machine but not in WSL (running Ubuntu 20)