In an effort to speed up frequently repeated runs of a particular script in my chain, I started serializing to disk custom objects that otherwise take too much time to create aggregately.
Using built-in Yaml and/or Marshal.
Yaml serializes fine to a seemingly healthy text file but produces the following error when trying to deserialize:
b2 = YAML::load(File.open("browserObj.yaml", 'r'))
Syck::TypeError: Invalid Regular expression: "/\\A\\s*\n ([a-zA-Z][-+.a-zA-Z\\d]*): ...and many more strange lines
However even trying to save to a binary file via Marshal errors:
puts File.open("browserObj.bin", 'w').write Marshal::dump($browser)
TypeError: can't dump TCPServer
# Marshal::dump($browser, File.open("browserObj.bin", 'wb')) # same error
By deliberately not doing $browser.close
at the end I have the option to keep this TCPServer alive and running after the lifetime of my Ruby script.
Any thoughts on how I can get away with this? I promise upon successful reloading to double-check the validity of any sockets/inner objects and simply re-initialize a whole new object if I have to.
Psych
, but how to switch fromSyck
if used internally byWatir
? – Vibraharp