How can I share a database connection across a forked process in Perl?

被刻印的时光 ゝ 提交于 2019-12-11 15:05:32

问题


I made the following programs in Perl before:

my $db = DBconnection with DB2

if ($pid = fork()) {
    #parent
} else {
    #child
    $db->execute("SELECT ****");
    exit;
}

wait();
$db->execute("SELECT ****");

I thought that it waited for the end of the child process to have wanted to do it and would operate it for DB by a pro-process.

In addition, DB is not connected to the contents of the error.

What's wrong?


回答1:


There is a lot of stuff you must do to allow a child process to use its parent's DBI handle. See this article on Perl Monks about DBI, fork, and clone.




回答2:


Try including this line of code in your child block:

$db->{InactiveDestroy} = 1;


来源:https://stackoverflow.com/questions/874434/how-can-i-share-a-database-connection-across-a-forked-process-in-perl

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