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

Open
opened this issue Oct 2, 2013 · 22 comments
Open

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

opened this issue Oct 2, 2013 · 22 comments
Labels

### palpha commented Oct 2, 2013

 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 Oct 2, 2013

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

### palpha commented Oct 2, 2013

 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 Oct 2, 2013

 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 Oct 2, 2013

 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 Oct 2, 2013

 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 Oct 2, 2013

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

### wuub commented Oct 2, 2013

 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 ;)
mentioned this issue Oct 3, 2013

### wuub commented Oct 5, 2013

 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 Oct 8, 2013

 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 Oct 8, 2013

 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 Oct 8, 2013

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

### palpha commented Oct 8, 2013

 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 Oct 19, 2013

 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 Jan 3, 2014

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

### hs3180 commented May 19, 2014

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

### jklemm commented Jul 15, 2014

 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 Aug 12, 2014

 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 Nov 10, 2014

 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 Aug 3, 2015

 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 Aug 3, 2015

 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 Oct 7, 2015

 @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.
mentioned this issue Apr 2, 2016

### 5j9 commented May 11, 2016 • edited

 Win 10 64-bit. Python 3.5.1 32-bit. Steps to reproduce: Open a python script. Run a repl. (ctrl+shift+p, type sublimerepl: python, press enter ) Try running the script in the repl. (ctrl+,, f) Close the repl tab (ctrl+w) Open another repl. 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 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.
added a commit to Drllap/SublimeREPL that referenced this issue Sep 12, 2016
 Change so that is_alive SubprocessRepl always returns True 
 389a6e5 
See:
wuub#271 (comment)
added a commit that referenced this issue Jan 28, 2017
 Merge pull request #351 from ehuss/winhandle 
 9314045 
Attempted fix for windows "handle is invalid" error. (Issue #271)
added a commit to neilalex/SublimeREPL that referenced this issue Apr 9, 2017
 Fixed according to wuub#271 
 900c3b4 
mentioned this issue Apr 21, 2017