Pharo Smalltalk image unresponsive with FileStream on Windows 10

191 Views Asked by At

I'm using a Pharo 6.1 image to do some CSV file processing. Sometimes my image just becomes unresponsive — I have to terminate the Pharo VM from Task Manager.

Is it necessary to use somethings like:

ensure:[toStream close]
ensure:[fromStream close]

What's a simple but reliable approach to reading and especially writing files with Pharo?

1

There are 1 best solutions below

0
philippeback On

The image is not really unresponsive but the UI thread for sure is when you do a long operation like reading a big CSV file.

The best would be to for a process for doing it.

Like in:

[ target doSomeLongThing ] fork.

You can view the process in the process browser from the world menu and terminate it there.

Now that is not really something one will think about when trying things out interactively in a playground.

What I do to alleviate this situation is twofold:

  1. Put these things in a test. Why? Because tests have a maximum duration and if things are stuck, they will come back with a time exceeded notification from the test.
  2. Start the Zinc REPL on a port, so that I can access the system from a web browser if the UI thread is kind of stuck and restart the UI thread.

I wish the interrupt key would work in all cases but well, it doesn't and is a solid annoyance.

I am of the opinion that images should be considered as discardable artifacts and CI job should be building them regularly (like daily) so that we have some recovery path.

This is not really cool as yes, using an image and being able to come back to it without having to rebuild stuff all the time when doing explorations shouldn't frustrate us with UI thread blockages. I hate that. I have an image that is stuck on restart from some Glamour problem, it is infuriating as it cannot be debugged or anything.

You can also use:

(FileLocation imageDirectory / 'somefile.csv') asFileReference readStreamDo: [ :stream |

     "do something with the stream" ].

This will do the ensure: bit for you. Cleaner. Easier.

For CSV, also give a shot to NeoCSV as it will do the file handling for you as well.

HTH