Joey Marino
3/27/2008 12:09:00 AM
[Note: parts of this message were removed to make it a legal post.]
I see,
I have a class to handle interfacing to the database. The initialization of
the class will connect to the db and another method will close the
connection and there are query functions for handling the queries and
results. This object is then passed into new objects on their
initialization. The problem comes in when I iterate through a set of objects
creating a fork for each one. After the first object I am getting a
"database went away error". My code looks like the following:
db = MySQL.new
fork do
obj1 = Object1.new(db)
obj1.addToDb
end
Process.wait
fork do
obj2 = Object2.new(db) #Object1 and Object2 are inherited from the same
superclass
ob2.addToDb #db error occurs here
end
Process.wait
db.closeDB
--output--
obj1 info added to db!
Error message: MySQL server has gone away
I know I am missing a key concept here. This is the first time I have worked
with forked processes.
On Wed, Mar 26, 2008 at 7:39 PM, Joel VanderWerf <vjoel@path.berkeley.edu>
wrote:
> Joey Marino wrote:
> > I want to fork a child process and use instantiated objects from the
> parent
> > process. Is this possible?
> >
> > obj = Object.new
> >
> > fork do
> > doSomething(obj)
> > end
>
> Yes, but it is a _copy_ of the original, so modifications in the child
> don't affect the parent.
>
> --
> vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407
>
>
--
Joey Marino