how to serialize an object using TCPServer inside?

给你一囗甜甜゛ 提交于 2019-11-28 01:56:52

问题


In an effort to speedup frequent 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 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.

来源:https://stackoverflow.com/questions/8838274/how-to-serialize-an-object-using-tcpserver-inside

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!