Message from discussion
How to fork child in "non persistent" way?
Received: by 10.58.164.162 with SMTP id yr2mr616996veb.29.1343721197302;
Tue, 31 Jul 2012 00:53:17 -0700 (PDT)
X-BeenThere: nodejs@googlegroups.com
Received: by 10.52.35.202 with SMTP id k10ls4273454vdj.0.gmail; Tue, 31 Jul
2012 00:53:01 -0700 (PDT)
Received: by 10.52.68.134 with SMTP id w6mr1325503vdt.6.1343721181782;
Tue, 31 Jul 2012 00:53:01 -0700 (PDT)
Date: Tue, 31 Jul 2012 00:53:01 -0700 (PDT)
From: Mariusz Nowak <mari...@medikoo.com>
To: nodejs@googlegroups.com
Message-Id: <633fff85-2349-48f1-9527-747919716899@googlegroups.com>
In-Reply-To: <cd63ffa9-3abf-49ad-b6b1-0856c25b7379@googlegroups.com>
References: <5f48b9ca-5912-4ed7-96ce-335b5ca98f71@googlegroups.com>
<28be4ee9-81b7-44af-a3f5-6b9c2ac14e09@googlegroups.com>
<cd63ffa9-3abf-49ad-b6b1-0856c25b7379@googlegroups.com>
Subject: Re: How to fork child in "non persistent" way?
MIME-Version: 1.0
Content-Type: multipart/mixed;
boundary="----=_Part_369_6230798.1343721181451"
------=_Part_369_6230798.1343721181451
Content-Type: multipart/alternative;
boundary="----=_Part_370_31205749.1343721181451"
------=_Part_370_31205749.1343721181451
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 7bit
Accidentally I just found very related
issue https://github.com/joyent/node/issues/2605
On Tuesday, July 31, 2012 9:15:14 AM UTC+2, Mariusz Nowak wrote:
>
> @Jeff If you're handling not detached child processes process will never
> 'exit' naturally, so waiting for 'exit' event means waiting forever. You
> need to either manually kill child process or manually kill master process,
> and you just can't do it in generic low-level module.
>
> I already found out, that what I was after is currently impossible. I can
> start other process within Node.js in not persistent way using spawn and
> detached set to true, but it will only work if I don't setup any
> communication between current process and one I'm creating. There's no way
> to have both detached process and communicate with it via IPC channel.
>
> Anyway I decided that what I wanted to achieve is not
> clean, creating background processes in generic modules is not great, and I
> gone other path, less ideal from the functionality point of view, but
> definitely cleaner.
>
>
> On Tuesday, July 31, 2012 2:52:41 AM UTC+2, Jeff Kingyens wrote:
>>
>> Using child_process.fork enables bi-directional message passing between
>> parent and child (see node.js documentation).
>> While im not sure exactly what you are trying to do, this functionality
>> should be all that you need.
>>
>> When the event loop in a node.js process is exhausted the process will
>> exit causing 'exit' event on process object.
>> You should handle this 'exit' event on the parent process and then send a
>> message to the child process to clean itself up.
>> If you need to do any cleanup on the parent after the child has closed
>> then wait on a final message from the child saying
>> its done. The details for you maybe be different, but this is the general
>> idea.
>>
>> Jeff
>>
>> On Friday, July 27, 2012 9:00:19 AM UTC-7, Mariusz Nowak wrote:
>>>
>>> I'd like to create fork (via child_process.fork) and make both master
>>> and child exit after all tasks in master process are done.
>>> When I do:
>>>
>>> var child = child_process.fork("foo.js");
>>>
>>> Process just hangs. I can of course exit it manually via `process.exit`,
>>> but it's a generic module, and I don't have information when it's ok to do
>>> so as there might be some other asynchronous tasks I'm not aware of.
>>>
>>> Is there any way to be informed that all event loops for current process
>>> have finished it's work? Something like process.lastTick, which would emit
>>> callback if there's no other event loops in a queue ?
>>>
>>> Thanks
>>>
>>>
------=_Part_370_31205749.1343721181451
Content-Type: text/html; charset=utf-8
Content-Transfer-Encoding: quoted-printable
Accidentally I just found very related issue https://github.com/joyent=
/node/issues/2605<br><br>On Tuesday, July 31, 2012 9:15:14 AM UTC+2, Marius=
z Nowak wrote:<blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-l=
eft: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;">@Jeff If you're =
handling not detached child processes process will never 'exit' naturally, =
so waiting for 'exit' event means waiting forever. You need to either manua=
lly kill child process or manually kill master process, and you just can't =
do it in generic low-level module.<div><br><div><div>I already found out, t=
hat what I was after is currently impossible. I can start other process wit=
hin Node.js in not persistent way using spawn and detached set to true, but=
it will only work if I don't setup any communication between current proce=
ss and one I'm creating. There's no way to have both detached process and c=
ommunicate with it via IPC channel.</div><div><br></div><div>Anyway I decid=
ed that what I wanted to achieve is not clean, creating backgroun=
d processes in generic modules is not great, and I gone other path, less id=
eal from the functionality point of view, but definitely cleaner.</div><div=
><br></div><div><br>On Tuesday, July 31, 2012 2:52:41 AM UTC+2, Jeff Kingye=
ns wrote:<blockquote class=3D"gmail_quote" style=3D"margin:0;margin-left:0.=
8ex;border-left:1px #ccc solid;padding-left:1ex">Using child_process.fork e=
nables bi-directional message passing between parent and child (see node.js=
documentation).<div>While im not sure exactly what you are trying to do, t=
his functionality should be all that you need.</div><div><br></div><div>Whe=
n the event loop in a node.js process is exhausted the process will exit ca=
using 'exit' event on process object.</div><div>You should handle this 'exi=
t' event on the parent process and then send a message to the child process=
to clean itself up.</div><div>If you need to do any cleanup on the parent =
after the child has closed then wait on a final message from the child sayi=
ng</div><div>its done. The details for you maybe be different, but this is =
the general idea.</div><div><br></div><div>Jeff</div><div><br>On Friday, Ju=
ly 27, 2012 9:00:19 AM UTC-7, Mariusz Nowak wrote:<blockquote class=3D"gmai=
l_quote" style=3D"margin:0;margin-left:0.8ex;border-left:1px #ccc solid;pad=
ding-left:1ex">I'd like to create fork (via child_process.fork) and make bo=
th master and child exit after all tasks in master process are done.<div>Wh=
en I do:</div><div><br></div><div>var child =3D child_process.fork("foo.js"=
);</div><div><br></div><div>Process just hangs. I can of course exit it man=
ually via `process.exit`, but it's a generic module, and I don't have infor=
mation when it's ok to do so as there might be some other asynchronous task=
s I'm not aware of.</div><div><br></div><div>Is there any way to be informe=
d that all event loops for current process have finished it's work? Somethi=
ng like process.lastTick, which would emit callback if there's no other eve=
nt loops in a queue ?</div><div><br></div><div>Thanks</div><div><br></div><=
/blockquote></div></blockquote></div></div></div></blockquote>
------=_Part_370_31205749.1343721181451--
------=_Part_369_6230798.1343721181451--