Archive for March, 2008

FYI – Ruby can’t serialize open file handles

March 28, 2008

I spent the last three weeks rebuilding my phylogenetics software pipeline in Ruby. I emigrated to Ruby from Perl for many reasons, one being Ruby’s emphasis on object-oriented scripting. Perl is not a good environment for constructing complex data structures, whereas Ruby (and Python and other next-generation scripting languages) use syntax which allows for easy expression of complex class hierarchies.

Object-oriented scripting in Ruby is especially beneficial for long-running software pipelines. At critical checkpoints in the pipeline, I serialize objects to disk. If the pipeline fails for any reason, it’s easy to later deserialize the Ruby objects and pick-up where the pipeline left-off. In theory, Ruby’s Marshal class is a godsend. In reality, there are some hangups.

My code includes a Simulation class, which contains a Log class, which contains an open file handle. When I attempt to serialize an instance of the Simulation class, Ruby throws a runtime error, complaining that Marshal.dump cannot dump the File class. Clearly, the Ruby interpreter is not intelligent enough to avoid dumping an open file handle.

The solution? = manually close all File objects before invoking Marshal.dump.

Uggh.


Follow

Get every new post delivered to your Inbox.