wuub / SublimeREPL

SublimeREPL - run an interpreter inside ST2 (Clojure, CoffeeScript, F#, Groovy, Haskell, Lua, MozRepl, NodeJS, Python, R, Ruby, Scala, shell or configure one yourself)
https://github.com/wuub/SublimeREPL
Other
2.14k stars 312 forks source link

Eval in REPL, "The handle is invalid" #271

Open palpha opened 10 years ago

palpha commented 10 years ago
Traceback (most recent call last):
  File "C:\Program Files\Sublime Text 3\sublime_plugin.py", line 543, in run_
    return self.run(edit, **args)
  File "---\AppData\Roaming\Sublime Text 3\Packages\SublimeREPL\text_transfer.py", line 123, in run
    for rv in manager.find_repl(external_id):
  File "---\AppData\Roaming\Sublime Text 3\Packages\SublimeREPL\sublimerepl.py", line 437, in find_repl
    if not (rv.repl and rv.repl.is_alive()):
  File "---\AppData\Roaming\Sublime Text 3\Packages\SublimeREPL\repls\subprocess_repl.py", line 185, in is_alive
    return self.popen.poll() is None
  File "X/subprocess.py", line 916, in poll
  File "X/subprocess.py", line 1131, in _internal_poll
OSError: [WinError 6] The handle is invalid

I got it working by changing the .poll() call to a simple self.popen != None, but that's almost certainly the wrong approach (commit).

wuub commented 10 years ago

Which version of OSX and which version of Sublime Text are you using?

palpha commented 10 years ago

It's Windows 8 and Sublime Text 3. I'm getting pretty much the same error in ST2, and the same "fix" works there.

Awesome plugin, by the way. Just about to force all my colleagues to check it out :).

wuub commented 10 years ago

Windows

Yeah, that;s what I wanted to write ;)

8

I need to get my hands on win8 machine. .poll()/.select() were misbehaving in the past and with win8 problem seems to be back :/

Until I find a way to fix it in core

   def is_alive(self):
       return True

is the best workaround. As far as I can tell nothing really bad will happen ;)

Your fix does exactly that, always returning True.

Just about to force all my colleagues to check it out :).

Which language? Python? :)

palpha commented 10 years ago

Ah. As I said, I didn't really attempt to figure out what the code does :).

I'm trying to get my colleagues to learn and use F#, so this is a good tool for them. Also, they're JavaScript people, so easy access to Node should come in handy. Having PowerShell in there is a very nice bonus. I'm constantly learning new languages, so this is the perfect plugin for me (donation sent).

One thing that would be nice is if REPL tabs in another tab group could be focused when they receive data. Having it steal focus when it's in the same group as the sender would probably be intrusive. I guess I should post this as a feature request :).

wuub commented 10 years ago

One thing that would be nice is if REPL tabs in another tab group could be focused when they receive data. Having it steal focus when it's in the same group as the sender would probably be intrusive. I guess I should post > this as a feature request :).

Hey, this is a good idea. Please open a feature request. It's easier to track this way.

(donation sent).

Believe me, I've noticed ;) Thank you ;-D

palpha commented 10 years ago

Done. Keep up the good work, it's really appreciated.

wuub commented 10 years ago

FYI I've found a way to get windows 8 http://windows.microsoft.com/en-us/windows-8/preview-iso

I really hope it has the same bugs ;)

wuub commented 10 years ago

I got it working by changing the .poll()

For some reason I am unable to recreate this problem on Windows 8.1 (32bit), ST3 beta and neither Python nor Powershell repls.

Can you describe your in closer detail? I might be able to hunt down someone with proper Win8 laptop soon ;)

jacalata commented 10 years ago

I just ran into this on my Win8 64bit laptop (using the REPL for SML, ST3). The traceback is identical to the one above and adding palpha's initial change fixed it.

palpha commented 10 years ago

Yup, I'm on Windows 8 (not 8.1) 64 bit as well.

I can't really find a pattern for when this works and when it doesn't. Switching syntax back and forth and sending to two different REPLs (Node and F#) triggered the problem (but not consistently), and so did opening a new Sublime window, creating a file, opening a Node REPL and eval:ing.

wuub commented 10 years ago

So it doesn't happen right after starting a repl?

palpha commented 10 years ago

Well, yes. Sometimes. Or most of the time. I'm usually good at discerning patterns, but I can't see it in this case :).

Try this: Open a fresh Sublime instance, no project. Open Node REPL New file, syntax JS, eval something Open F# REPL Set syntax of file to F#, eval something = WinError 6, The handle is invalid

I don't know if this is the simplest possible repro, but it seems consistent.

mFingers commented 10 years ago

I might have a clue to why this sometimes doesn't work. Last time the key bindings stopped working for me (using the R REPL), I checked Task Manager, and found "R for windows terminal front end" still running. That wasn't expected (I always use the q() command in the REPL to shut it down), so I killed the process, opened a new REPL in ST2, and the key bindings started working again. My thought is maybe the plugin is trying to send commands to a valid repl, but an invalid window (in ST2) for that repl. @palpha, maybe next time the keyboard commands stop working for you, check task manager to see if fsi is still running. Then try killing it to and see if the shortcuts work again.

renkun-ken commented 10 years ago

My environment is Win8.1 64-bit, ST3, eval usually does not work.

hs3180 commented 10 years ago

I am in Win8.1 64-bit, this problem occurred in both ST2/3

jklemm commented 10 years ago

I am in Win7 64-bit Ultimate with ST3, trying the Ctrl+, f, occurs the same error.

If I change the "subprocess_repl.py" file, not works but the error changes.

gwenzek commented 9 years ago

I've faced the same issue on windows 8, and

   def is_alive(self):
       return True

did the trick (note: you have to restart sublime to see the result of the quick-fix)

j9ac9k commented 9 years ago

So I just encountered this issue on Windows 7 x64 with Sublime Text 3. I changed to

    def is_alive(self):
        return True

but when I restarted and fired up a new repl window, I got a bunch of errors. Changing back to:

    def is_alive(self):
        return self.popen.poll() is None

resulted in REPL working as intended... let me know if there is any testing I can do

stianlagstad commented 8 years ago

I had this problem using R, and it turns out my problem was due to me opening sublime text from the command line. This solution from stackoverflow solved the problem for me: http://stackoverflow.com/questions/10438508/error6-while-trying-to-use-sublime-text-to-msbuild

stianlagstad commented 8 years ago

That was premature. It solved the problem for the first thing I send to the REPL, but the error comes for each command I use after that. Editing is_alive in subprocess_repl.py as suggested does the trick though.

Z-Clive commented 8 years ago

@wuub

Same problem ([WinError 6] The handle is invalid) on Windows 10 64bit with Sublime 3 and Python 3.5 installed. This work-around:

def is_alive(self):
    return True

did the trick (though not perfect).

Hopefully this could be fixed soon. ;) Thanks for the package btw.

5j9 commented 8 years ago

Win 10 64-bit. Python 3.5.1 32-bit.

Steps to reproduce:

  1. Open a python script.
  2. Run a repl. (ctrl+shift+p, type sublimerepl: python, press enter )
  3. Try running the script in the repl. (ctrl+,, f)
  4. Close the repl tab (ctrl+w)
  5. Open another repl.
  6. Try running the script again.

Traceback:

Traceback (most recent call last):
  File "C:\Program Files\Sublime Text 3\sublime_plugin.py", line 231, in run_callback
    expr()
  File "C:\Program Files\Sublime Text 3\sublime_plugin.py", line 270, in <lambda>
    run_callback('on_close', callback, lambda: callback.on_close(v))
  File "C:\Users\a\AppData\Roaming\Sublime Text 3\Packages\SublimeREPL\sublimerepl.py", line 748, in on_close
    rv.on_close()
  File "C:\Users\a\AppData\Roaming\Sublime Text 3\Packages\SublimeREPL\sublimerepl.py", line 262, in on_close
    self.repl.close()
  File "C:\Users\a\AppData\Roaming\Sublime Text 3\Packages\SublimeREPL\repls\repl.py", line 59, in close
    if self.is_alive():
  File "C:\Users\a\AppData\Roaming\Sublime Text 3\Packages\SublimeREPL\repls\subprocess_repl.py", line 209, in is_alive
    return self.popen.poll() is None
  File "./subprocess.py", line 938, in poll
  File "./subprocess.py", line 1153, in _internal_poll
OSError: [WinError 6] The handle is invalid

mFingers's trick, finding the zombie process and killing it, worked for me. So did the the suggested return True patch.

Boscop commented 2 years ago

I'm on Win 10 with TidalCycles (ghci, Haskell), I followed the instructions here: https://tidalcycles.org/docs/getting-started/editor/Sublime_Text/#configuration-for-tidal

When I do Ctrl+Shift+P -> “Sublime REPL: Tidal”, it opens a new tab with ghci as expected, but evaluating code (with one of the key combos, e.g. { "keys": ["ctrl+,", "l"], "command": "repl_transfer_current", "args": {"scope": "lines"}}) doesn't work, I get this error:

Traceback (most recent call last):
  File "C:\Program Files\Sublime Text 3\sublime_plugin.py", line 1082, in run_
    return self.run(edit, **args)
  File "C:\Users\me\AppData\Roaming\Sublime Text 3\Packages\SublimeREPL\text_transfer.py", line 141, in run
    for rv in manager.find_repl(external_id):
  File "C:\Users\me\AppData\Roaming\Sublime Text 3\Packages\SublimeREPL\sublimerepl.py", line 470, in find_repl
    if not (rv.repl and rv.repl.is_alive()):
  File "C:\Users\me\AppData\Roaming\Sublime Text 3\Packages\SublimeREPL\repls\subprocess_repl.py", line 209, in is_alive
    return self.popen.poll() is None
  File "./python3.3/subprocess.py", line 930, in poll
  File "./python3.3/subprocess.py", line 1145, in _internal_poll
OSError: [WinError 6] The handle is invalid

Any idea how to make it work? :)


Edit: I restarted Sublime, now when I try to evaluate code, I get this error:

error: Cannot find REPL for 'plain'

And every time I do Ctrl+Shift+P -> “Sublime REPL: Tidal”, it just opens another ghci tab:

image

My test.tidal file is opened in plain text mode. There is no Tidal entry here:

image