orbitalquark / textadept

Textadept is a fast, minimalist, and remarkably extensible cross-platform text editor for programmers.
https://orbitalquark.github.io/textadept
MIT License
640 stars 38 forks source link

`spawn_proc:close()` raises an error in Textadept 12.0 alpha #354

Closed davidvontamar closed 1 year ago

davidvontamar commented 1 year ago

I'm testing now Textadept 12.0 alpha and the command spawn_proc:close(), which previously worked, now appears to be broken.

The following code:

local handle = os.spawn('echo "Hello"')
local line = handle:read()
while line do
    line = handle:read()
end
handle:close()

Will raise an error in Textadept:

calling 'close' on bad self (process terminated)
orbitalquark commented 1 year ago

I'm not sure that this is a bug. handle:close() closes a process' stdin. Your loop reads from the process' stdout until there is none left (i.e. the process finished). I would expect that attempting to close stdin on a completed process would cause an error.

davidvontamar commented 1 year ago

Is this a new behavior introduced in Textadept 12.0? Textadept 11.4 did not raise such an error. Is it safe to remove the handle:close() command in Textadept 12.0? In addition, is there a way in which I can check if the process still needs closing?

orbitalquark commented 1 year ago

You can remove handle:close(). It's only needed if you're sending stdin to the process. Processes clean up after themselves, so you don't have to do anything. I don't know if you're using the Qt or GTK version, but it's possible that the Qt version's internal process implementation raises this error while the GTK version doesn't.

davidvontamar commented 1 year ago

OK, thanks! I'm using the Qt version. I like Qt and all my desktop apps are Qt apps. I'm very happy that Textadept transitioned to Qt now.