How to find unclosed file handles in Squeak?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

How to find unclosed file handles in Squeak?

Christoph Thiede

Simple question, probably we already have a helper method for it, but I did not found any yet:

Often, way too often, I encounter some old code (or some stupid code written by myself) that uses #readStream to read a file and forgets to close it again.

Apart from the fact that #readStream is a quite dangerous selector, I wish I could find these unclosed file streams and close them manually without restarting my entire image.

Is there any quick way to do this? "Smalltalk snapshot: false andQuit: false" does not seem to do the trick, and I would prefer a less brutal approach.

Something like "Utilities exploreUnclosedFileStreams" would be perfect ...


Best,

Christoph



Carpe Squeak!
Reply | Threaded
Open this post in threaded view
|

Re: How to find unclosed file handles in Squeak?

Karl Ramberg
Stream allSubInstances ?

Best,
Karl

On Thu, Oct 1, 2020 at 9:13 PM Thiede, Christoph <[hidden email]> wrote:

Simple question, probably we already have a helper method for it, but I did not found any yet:

Often, way too often, I encounter some old code (or some stupid code written by myself) that uses #readStream to read a file and forgets to close it again.

Apart from the fact that #readStream is a quite dangerous selector, I wish I could find these unclosed file streams and close them manually without restarting my entire image.

Is there any quick way to do this? "Smalltalk snapshot: false andQuit: false" does not seem to do the trick, and I would prefer a less brutal approach.

Something like "Utilities exploreUnclosedFileStreams" would be perfect ...


Best,

Christoph




Reply | Threaded
Open this post in threaded view
|

Re: How to find unclosed file handles in Squeak?

Levente Uzonyi
In reply to this post by Christoph Thiede
Hi Christoph,

On Thu, 1 Oct 2020, Thiede, Christoph wrote:

>
> Simple question, probably we already have a helper method for it, but I did not found any yet:
>
> Often, way too often, I encounter some old code (or some stupid code written by myself) that uses #readStream to read a file and forgets to close it again.
>
> Apart from the fact that #readStream is a quite dangerous selector, I wish I could find these unclosed file streams and close them manually without restarting my entire image.
>
> Is there any quick way to do this? "Smalltalk snapshot: false andQuit: false" does not seem to do the trick, and I would prefer a less brutal approach.
>
> Something like "Utilities exploreUnclosedFileStreams" would be perfect ...
Try this: StandardFileStream registry.
Note that you can't just close all files there, but the files you are
looking for are there.


Levente

>
>
> Best,
>
> Christoph
>
>
>

Reply | Threaded
Open this post in threaded view
|

Re: How to find unclosed file handles in Squeak?

Christoph Thiede

Hi Karl, Hi Levente,


Stream allSubInstances ?


I tried this earlier today, but when I filtered the very long list for streams that are open and whose fullName is notNil, I did not find the relevant files.

Try this: StandardFileStream registry.

Thank you, this looks promising! I will try it if I encounter a similar problem the next time. :-)

Best,
Christoph

Von: Squeak-dev <[hidden email]> im Auftrag von Levente Uzonyi <[hidden email]>
Gesendet: Donnerstag, 1. Oktober 2020 21:58:58
An: The general-purpose Squeak developers list
Betreff: Re: [squeak-dev] How to find unclosed file handles in Squeak?
 
Hi Christoph,

On Thu, 1 Oct 2020, Thiede, Christoph wrote:

>
> Simple question, probably we already have a helper method for it, but I did not found any yet:
>
> Often, way too often, I encounter some old code (or some stupid code written by myself) that uses #readStream to read a file and forgets to close it again.
>
> Apart from the fact that #readStream is a quite dangerous selector, I wish I could find these unclosed file streams and close them manually without restarting my entire image.
>
> Is there any quick way to do this? "Smalltalk snapshot: false andQuit: false" does not seem to do the trick, and I would prefer a less brutal approach.
>
> Something like "Utilities exploreUnclosedFileStreams" would be perfect ...

Try this: StandardFileStream registry.
Note that you can't just close all files there, but the files you are
looking for are there.


Levente

>
>
> Best,
>
> Christoph
>
>
>


Carpe Squeak!