nicosantangelo / sublime-gulp

Run Gulp tasks and use snippets from Sublime Text
https://sublime-gulp.nicosantangelo.com/
MIT License
155 stars 18 forks source link

Kill running watch task not working #89

Closed FelixBoers closed 6 years ago

FelixBoers commented 6 years ago

After running Gulp: Kill running tasks the node.exe process keeps running. Also Gulp: Kill specific running task doesn't show anything.

I've created an GitHub project with which I can reproduce the problem: https://github.com/flex87/sublime-gulp-kill-watch-task-problem

This is my environment:

Component Version
OS Windows 10 x64
NodeJS v8.5.0
Gulp 3.9.1
Sublime Text 3 Build 3150

This is my gulpfile:

var gulp = require('gulp');

gulp.task('default', function() {
    gulp.watch('watch.js', function(evt) {
        console.log('file ' + evt.path + ' was ' + evt.type);
    });
});

This is what I can read from the console window of Sublime Text after starting the default Gulp task:

Could not import subprocess32 module, falling back to subprocess module

And this is what it shows after running the Gulp: Kill running tasks command:

Traceback (most recent call last):
  File "C:\Users\boers\AppData\Roaming\Sublime Text 3\Packages\Gulp\cross_platform_codecs.py", line 18, in force_decode
    text = text.decode('utf-8')
UnicodeDecodeError: 'utf-8' codec can't decode byte 0x81 in position 74: invalid start byte

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Program Files\Sublime Text 3\sublime_plugin.py", line 797, in run_
    return self.run()
  File "C:\Users\boers\AppData\Roaming\Sublime Text 3\Packages\Gulp\base_command.py", line 30, in run
    self.work()
  File "C:\Users\boers\AppData\Roaming\Sublime Text 3\Packages\Gulp\gulp.py", line 284, in work
    ProcessCache.refresh()
  File "C:\Users\boers\AppData\Roaming\Sublime Text 3\Packages\Gulp\caches.py", line 31, in refresh
    cls.each(remove_dead)
  File "C:\Users\boers\AppData\Roaming\Sublime Text 3\Packages\Gulp\caches.py", line 56, in each
    fn(process)
  File "C:\Users\boers\AppData\Roaming\Sublime Text 3\Packages\Gulp\caches.py", line 29, in remove_dead
    if not process.is_alive():
  File "C:\Users\boers\AppData\Roaming\Sublime Text 3\Packages\Gulp\cross_platform_process.py", line 95, in is_alive
    return self._pid_exists()
  File "C:\Users\boers\AppData\Roaming\Sublime Text 3\Packages\Gulp\cross_platform_process.py", line 106, in _pid_exists
    found = str(self.pid) in CrossPlatformCodecs.force_decode(stdout)
  File "C:\Users\boers\AppData\Roaming\Sublime Text 3\Packages\Gulp\cross_platform_codecs.py", line 21, in force_decode
    text = self.decode_windows_line(text)
  File "C:\Users\boers\AppData\Roaming\Sublime Text 3\Packages\Gulp\cross_platform_codecs.py", line 41, in decode_windows_line
    return text.decode("cp" + chcp)
LookupError: unknown encoding: cp850.

Is there something I'm doing wrong?

nicosantangelo commented 6 years ago

Hum I don't think you're doing anything wrong, it seems to be a bug on the Package. For what I can see, it's encoding problem.

The package uses os.kill(self.pid, 0) for UNIX based systems (equivalent to calling kill on the terminal) but, for Windows, it uses tasklist.exe. The exception we're seeing seems to be from trying to decode the result of running: C:\Windows\system32\tasklist.exe /FI PID eq {PROCESS_PID_HERE} /FO CSV

The weird thing is that the decode error is coming from asking the OS the preferred encoding, and trying to decode using that (cp850 in your case).

So!

 return text.decode("cp" + chcp)

for

try:
  return text.decode("cp" + chcp)
except LookupError:
  return text
FelixBoers commented 6 years ago

Hey @NicoSantangelo. Thanks for your help. The problem was that on a german system chcp returns: Aktive Codepage: 850.\r\n

So after invoking .stripe() and .split(" ")[-1] the name of the codepage will be 850. which is wrong. In order to make it work we've to remove the dot too.

I've submitted a pull request #90

Now everything works fine! Have a nice day