March 08, 2010
I don't know any way of doing this besides spawning a separate thread that a) starts the process, b) waits for it to complete, and c) calls the callback function/delegate.

Is this what you had in mind?

-Lars


Sean Kelly wrote:
> I'm not sure if this is supported in Windows, but if so, it might be nice if I could set a callback that would be executed when the process completes.
> 
> On Mar 3, 2010, at 9:44 AM, Lars Tandle Kyllingstad wrote:
> 
>> Hi,
>>
>> Recently, I found myself in need of the functionality that is (or should have been) in std.process, but unfortunately I found it lacking in many respects.  Assuming that improving it currently isn't at the top of the to-do list for Phobos, I decided not to wait, and rather to write my own version.  If you want you can check it out here:
>>
>> Code:   http://github.com/kyllingstad/ltk/blob/master/ltk/process.d Docs:   http://kyllingen.net/code/ltk/doc/process.html
>>
>> I don't know if any of it is usable for Phobos, but if it is, I'd be happy to contribute.
>>
>> I've tried to write it in the style of std.concurrency, with a function spawnProcess() that returns a Pid struct.  Currently it is for POSIX only, since I have no experience at all with the Windows API.
>>
>> -Lars
>> _______________________________________________
>> phobos mailing list
>> phobos at puremagic.com
>> http://lists.puremagic.com/mailman/listinfo/phobos
> 
> _______________________________________________
> phobos mailing list
> phobos at puremagic.com
> http://lists.puremagic.com/mailman/listinfo/phobos


-- 
Lars Tandle Kyllingstad
@: lars at kyllingen.net
#: 40233221
w: http://www.kyllingen.net
March 08, 2010
I think what Sean is trying to say is he wants that feature on windows if it is supported.  It seemed like he was implying that it was available on Linux and if windows supported it, it should be available as an abstract function.

I think you can do this on windows with a asynchronous event, but I'm not sure.  But I think you'd have to do the thread method for POSIX OSes.  I don't think this is an important feature to add, a hidden thread spawn in a method is not a good idea.

-Steve



----- Original Message ----
> From: Lars Tandle Kyllingstad <lars at kyllingen.net>
> 
> I don't know any way of doing this besides spawning a separate thread that a) starts the process, b) waits for it to complete, and c) calls the callback function/delegate.
> 
> Is this what you had in mind?
> 
> -Lars
> 
> 
> Sean Kelly wrote:
> > I'm not sure if this is supported in Windows, but if so, it might be nice if I
> could set a callback that would be executed when the process completes.
> > 



March 08, 2010
It doesn't necessarily require hiding anything from the user, it could be made very explicit both in the documentation and in the function signature.

   Tid spawnProcessWaitingThread
     (string name, void function() onComplete);

However, it can be argued that it probably won't save much typing, since the new thread-spawning function has such a terse syntax:

   spawnProcessWaitingThread
     ("firefox", { ... // when Firefox exits, do this });

vs.

   spawn({
     spawnProcess("firefox").wait();
     ... // when Firefox exits, do this
   });

-Lars



Steve Schveighoffer wrote:
> I think what Sean is trying to say is he wants that feature on windows if it is supported.  It seemed like he was implying that it was available on Linux and if windows supported it, it should be available as an abstract function.
> 
> I think you can do this on windows with a asynchronous event, but I'm not sure.  But I think you'd have to do the thread method for POSIX OSes.  I don't think this is an important feature to add, a hidden thread spawn in a method is not a good idea.
> 
> -Steve
> 
> 
> 
> ----- Original Message ----
>> From: Lars Tandle Kyllingstad <lars at kyllingen.net>
>>
>> I don't know any way of doing this besides spawning a separate thread that a) starts the process, b) waits for it to complete, and c) calls the callback function/delegate.
>>
>> Is this what you had in mind?
>>
>> -Lars
>>
>>
>> Sean Kelly wrote:
>>> I'm not sure if this is supported in Windows, but if so, it might be nice if I
>> could set a callback that would be executed when the process completes.
> 
> 
> 
> _______________________________________________
> phobos mailing list
> phobos at puremagic.com
> http://lists.puremagic.com/mailman/listinfo/phobos


-- 
Lars Tandle Kyllingstad
@: lars at kyllingen.net
#: 40233221
w: http://www.kyllingen.net
March 08, 2010
In *nix you can set a signal handler to be notified when a child process completes.  But the restrictions on what can be done inside a signal handler are such that maybe executing a callback from inside one isn't a good idea anyway.

On Mar 8, 2010, at 12:22 AM, Lars Tandle Kyllingstad wrote:

> I don't know any way of doing this besides spawning a separate thread that a) starts the process, b) waits for it to complete, and c) calls the callback function/delegate.
> 
> Is this what you had in mind?
> 
> -Lars
> 
> 
> Sean Kelly wrote:
>> I'm not sure if this is supported in Windows, but if so, it might be nice if I could set a callback that would be executed when the process completes.
>> On Mar 3, 2010, at 9:44 AM, Lars Tandle Kyllingstad wrote:
>>> Hi,
>>> 
>>> Recently, I found myself in need of the functionality that is (or should have been) in std.process, but unfortunately I found it lacking in many respects.  Assuming that improving it currently isn't at the top of the to-do list for Phobos, I decided not to wait, and rather to write my own version.  If you want you can check it out here:
>>> 
>>> Code:   http://github.com/kyllingstad/ltk/blob/master/ltk/process.d Docs:   http://kyllingen.net/code/ltk/doc/process.html
>>> 
>>> I don't know if any of it is usable for Phobos, but if it is, I'd be happy to contribute.
>>> 
>>> I've tried to write it in the style of std.concurrency, with a function spawnProcess() that returns a Pid struct.  Currently it is for POSIX only, since I have no experience at all with the Windows API.
>>> 
>>> -Lars
>>> _______________________________________________
>>> phobos mailing list
>>> phobos at puremagic.com
>>> http://lists.puremagic.com/mailman/listinfo/phobos
>> _______________________________________________
>> phobos mailing list
>> phobos at puremagic.com
>> http://lists.puremagic.com/mailman/listinfo/phobos
> 
> 
> -- 
> Lars Tandle Kyllingstad
> @: lars at kyllingen.net
> #: 40233221
> w: http://www.kyllingen.net
> _______________________________________________
> phobos mailing list
> phobos at puremagic.com
> http://lists.puremagic.com/mailman/listinfo/phobos

March 08, 2010
I didn't even think of that, but you're right, of course.  The parent gets a SIGCHLD when the child terminates.  I wonder if it's possible to restrict the callback so that it's safe to call it from a signal handler?  It would have to be nothrow, that's for sure, but that's probably not enough.  It is all too easy to make thread-unsafe code with signal handlers.  Is it possible to mark functions or delegates with 'shared', so they only operate on shared data?

-Lars


Sean Kelly wrote:
> In *nix you can set a signal handler to be notified when a child process completes.  But the restrictions on what can be done inside a signal handler are such that maybe executing a callback from inside one isn't a good idea anyway.
> 
> On Mar 8, 2010, at 12:22 AM, Lars Tandle Kyllingstad wrote:
> 
>> I don't know any way of doing this besides spawning a separate thread that a) starts the process, b) waits for it to complete, and c) calls the callback function/delegate.
>>
>> Is this what you had in mind?
>>
>> -Lars
>>
>>
>> Sean Kelly wrote:
>>> I'm not sure if this is supported in Windows, but if so, it might be nice if I could set a callback that would be executed when the process completes.
>>> On Mar 3, 2010, at 9:44 AM, Lars Tandle Kyllingstad wrote:
>>>> Hi,
>>>>
>>>> Recently, I found myself in need of the functionality that is (or should have been) in std.process, but unfortunately I found it lacking in many respects.  Assuming that improving it currently isn't at the top of the to-do list for Phobos, I decided not to wait, and rather to write my own version.  If you want you can check it out here:
>>>>
>>>> Code:   http://github.com/kyllingstad/ltk/blob/master/ltk/process.d Docs:   http://kyllingen.net/code/ltk/doc/process.html
>>>>
>>>> I don't know if any of it is usable for Phobos, but if it is, I'd be happy to contribute.
>>>>
>>>> I've tried to write it in the style of std.concurrency, with a function spawnProcess() that returns a Pid struct.  Currently it is for POSIX only, since I have no experience at all with the Windows API.
>>>>
>>>> -Lars
>>>> _______________________________________________
>>>> phobos mailing list
>>>> phobos at puremagic.com
>>>> http://lists.puremagic.com/mailman/listinfo/phobos
>>> _______________________________________________
>>> phobos mailing list
>>> phobos at puremagic.com
>>> http://lists.puremagic.com/mailman/listinfo/phobos
>>
>> -- 
>> Lars Tandle Kyllingstad
>> @: lars at kyllingen.net
>> #: 40233221
>> w: http://www.kyllingen.net
>> _______________________________________________
>> phobos mailing list
>> phobos at puremagic.com
>> http://lists.puremagic.com/mailman/listinfo/phobos
> 
> _______________________________________________
> phobos mailing list
> phobos at puremagic.com
> http://lists.puremagic.com/mailman/listinfo/phobos


-- 
Lars Tandle Kyllingstad
@: lars at kyllingen.net
#: 40233221
w: http://www.kyllingen.net
March 08, 2010
I would not do this.  A signal handler has no synchronization with the rest of the code, so you are not guaranteed to be in a sane state.  In addition, you can't catch a signal for just one child process, you have to catch them all.

Plus the user could have registered a signal handler for that signal, making the library or user code not work right.  I think signals are just too blunt an instrument to make this work.

-Steve



----- Original Message ----
> From: Lars Tandle Kyllingstad <lars at kyllingen.net>
> 
> I didn't even think of that, but you're right, of course.  The parent gets a SIGCHLD when the child terminates.  I wonder if it's possible to restrict the callback so that it's safe to call it from a signal handler?  It would have to be nothrow, that's for sure, but that's probably not enough.  It is all too easy to make thread-unsafe code with signal handlers.  Is it possible to mark functions or delegates with 'shared', so they only operate on shared data?
> 
> -Lars
> 
> 
> Sean Kelly wrote:
> > In *nix you can set a signal handler to be notified when a child process
> completes.  But the restrictions on what can be done inside a signal handler are such that maybe executing a callback from inside one isn't a good idea anyway.
> > 
> > On Mar 8, 2010, at 12:22 AM, Lars Tandle Kyllingstad wrote:
> > 
> >> I don't know any way of doing this besides spawning a separate thread that a)
> starts the process, b) waits for it to complete, and c) calls the callback function/delegate.
> >> 
> >> Is this what you had in mind?
> >> 
> >> -Lars
> >> 
> >> 
> >> Sean Kelly wrote:
> >>> I'm not sure if this is supported in Windows, but if so, it might be nice if
> I could set a callback that would be executed when the process completes.
> >>> On Mar 3, 2010, at 9:44 AM, Lars Tandle Kyllingstad wrote:
> >>>> Hi,
> >>>> 
> >>>> Recently, I found myself in need of the functionality that is (or should
> have been) in std.process, but unfortunately I found it lacking in many respects.  Assuming that improving it currently isn't at the top of the to-do list for Phobos, I decided not to wait, and rather to write my own version.  If you want you can check it out here:
> >>>> 
> >>>> Code:   http://github.com/kyllingstad/ltk/blob/master/ltk/process.d Docs:   http://kyllingen.net/code/ltk/doc/process.html
> >>>> 
> >>>> I don't know if any of it is usable for Phobos, but if it is, I'd be happy
> to contribute.
> >>>> 
> >>>> I've tried to write it in the style of std.concurrency, with a function
> spawnProcess() that returns a Pid struct.  Currently it is for POSIX only, since I have no experience at all with the Windows API.
> >>>> 
> >>>> -Lars
> >>>> _______________________________________________
> >>>> phobos mailing list
> >>>> phobos at puremagic.com
> >>>> http://lists.puremagic.com/mailman/listinfo/phobos
> >>> _______________________________________________
> >>> phobos mailing list
> >>> phobos at puremagic.com
> >>> http://lists.puremagic.com/mailman/listinfo/phobos
> >> 
> >> -- Lars Tandle Kyllingstad
> >> @: lars at kyllingen.net
> >> #: 40233221
> >> w: http://www.kyllingen.net
> >> _______________________________________________
> >> phobos mailing list
> >> phobos at puremagic.com
> >> http://lists.puremagic.com/mailman/listinfo/phobos
> > 
> > _______________________________________________
> > phobos mailing list
> > phobos at puremagic.com
> > http://lists.puremagic.com/mailman/listinfo/phobos
> 
> 
> -- Lars Tandle Kyllingstad
> @: lars at kyllingen.net
> #: 40233221
> w: http://www.kyllingen.net
> _______________________________________________
> phobos mailing list
> phobos at puremagic.com
> http://lists.puremagic.com/mailman/listinfo/phobos




March 08, 2010
Like Sean, I don't think going with SIGCHILD is a good idea. It's not only about thread safety, but mostly about reentrancy of system functions.

Andrei

Lars Tandle Kyllingstad wrote:
> I didn't even think of that, but you're right, of course.  The parent gets a SIGCHLD when the child terminates.  I wonder if it's possible to restrict the callback so that it's safe to call it from a signal handler?  It would have to be nothrow, that's for sure, but that's probably not enough.  It is all too easy to make thread-unsafe code with signal handlers.  Is it possible to mark functions or delegates with 'shared', so they only operate on shared data?
> 
> -Lars
> 
> 
> Sean Kelly wrote:
>> In *nix you can set a signal handler to be notified when a child process completes.  But the restrictions on what can be done inside a signal handler are such that maybe executing a callback from inside one isn't a good idea anyway.
>>
>> On Mar 8, 2010, at 12:22 AM, Lars Tandle Kyllingstad wrote:
>>
>>> I don't know any way of doing this besides spawning a separate thread that a) starts the process, b) waits for it to complete, and c) calls the callback function/delegate.
>>>
>>> Is this what you had in mind?
>>>
>>> -Lars
>>>
>>>
>>> Sean Kelly wrote:
>>>> I'm not sure if this is supported in Windows, but if so, it might be
>>>> nice if I could set a callback that would be executed when the
>>>> process completes.
>>>> On Mar 3, 2010, at 9:44 AM, Lars Tandle Kyllingstad wrote:
>>>>> Hi,
>>>>>
>>>>> Recently, I found myself in need of the functionality that is (or should have been) in std.process, but unfortunately I found it lacking in many respects.  Assuming that improving it currently isn't at the top of the to-do list for Phobos, I decided not to wait, and rather to write my own version.  If you want you can check it out here:
>>>>>
>>>>> Code:   http://github.com/kyllingstad/ltk/blob/master/ltk/process.d Docs:   http://kyllingen.net/code/ltk/doc/process.html
>>>>>
>>>>> I don't know if any of it is usable for Phobos, but if it is, I'd be happy to contribute.
>>>>>
>>>>> I've tried to write it in the style of std.concurrency, with a function spawnProcess() that returns a Pid struct.  Currently it is for POSIX only, since I have no experience at all with the Windows API.
>>>>>
>>>>> -Lars
>>>>> _______________________________________________
>>>>> phobos mailing list
>>>>> phobos at puremagic.com
>>>>> http://lists.puremagic.com/mailman/listinfo/phobos
>>>> _______________________________________________
>>>> phobos mailing list
>>>> phobos at puremagic.com
>>>> http://lists.puremagic.com/mailman/listinfo/phobos
>>>
>>> -- 
>>> Lars Tandle Kyllingstad
>>> @: lars at kyllingen.net
>>> #: 40233221
>>> w: http://www.kyllingen.net
>>> _______________________________________________
>>> phobos mailing list
>>> phobos at puremagic.com
>>> http://lists.puremagic.com/mailman/listinfo/phobos
>>
>> _______________________________________________
>> phobos mailing list
>> phobos at puremagic.com
>> http://lists.puremagic.com/mailman/listinfo/phobos
> 
> 
March 08, 2010
Right.  Upon reflection the best approach is probably just to launch a thread to block on wait().  It won't consume any CPU cycles waiting anyway.

On Mar 8, 2010, at 1:08 PM, Andrei Alexandrescu wrote:

> Like Sean, I don't think going with SIGCHILD is a good idea. It's not only about thread safety, but mostly about reentrancy of system functions.
> 
> Andrei
> 
> Lars Tandle Kyllingstad wrote:
>> I didn't even think of that, but you're right, of course.  The parent gets a SIGCHLD when the child terminates.  I wonder if it's possible to restrict the callback so that it's safe to call it from a signal handler?  It would have to be nothrow, that's for sure, but that's probably not enough.  It is all too easy to make thread-unsafe code with signal handlers.  Is it possible to mark functions or delegates with 'shared', so they only operate on shared data?
>> -Lars
>> Sean Kelly wrote:
>>> In *nix you can set a signal handler to be notified when a child process completes.  But the restrictions on what can be done inside a signal handler are such that maybe executing a callback from inside one isn't a good idea anyway.
>>> 
>>> On Mar 8, 2010, at 12:22 AM, Lars Tandle Kyllingstad wrote:
>>> 
>>>> I don't know any way of doing this besides spawning a separate thread that a) starts the process, b) waits for it to complete, and c) calls the callback function/delegate.
>>>> 
>>>> Is this what you had in mind?
>>>> 
>>>> -Lars
>>>> 
>>>> 
>>>> Sean Kelly wrote:
>>>>> I'm not sure if this is supported in Windows, but if so, it might be nice if I could set a callback that would be executed when the process completes.
>>>>> On Mar 3, 2010, at 9:44 AM, Lars Tandle Kyllingstad wrote:
>>>>>> Hi,
>>>>>> 
>>>>>> Recently, I found myself in need of the functionality that is (or should have been) in std.process, but unfortunately I found it lacking in many respects.  Assuming that improving it currently isn't at the top of the to-do list for Phobos, I decided not to wait, and rather to write my own version.  If you want you can check it out here:
>>>>>> 
>>>>>> Code:   http://github.com/kyllingstad/ltk/blob/master/ltk/process.d Docs:   http://kyllingen.net/code/ltk/doc/process.html
>>>>>> 
>>>>>> I don't know if any of it is usable for Phobos, but if it is, I'd be happy to contribute.
>>>>>> 
>>>>>> I've tried to write it in the style of std.concurrency, with a function spawnProcess() that returns a Pid struct.  Currently it is for POSIX only, since I have no experience at all with the Windows API.
>>>>>> 
>>>>>> -Lars
>>>>>> _______________________________________________
>>>>>> phobos mailing list
>>>>>> phobos at puremagic.com
>>>>>> http://lists.puremagic.com/mailman/listinfo/phobos
>>>>> _______________________________________________
>>>>> phobos mailing list
>>>>> phobos at puremagic.com
>>>>> http://lists.puremagic.com/mailman/listinfo/phobos
>>>> 
>>>> -- 
>>>> Lars Tandle Kyllingstad
>>>> @: lars at kyllingen.net
>>>> #: 40233221
>>>> w: http://www.kyllingen.net
>>>> _______________________________________________
>>>> phobos mailing list
>>>> phobos at puremagic.com
>>>> http://lists.puremagic.com/mailman/listinfo/phobos
>>> 
>>> _______________________________________________
>>> phobos mailing list
>>> phobos at puremagic.com
>>> http://lists.puremagic.com/mailman/listinfo/phobos
> _______________________________________________
> phobos mailing list
> phobos at puremagic.com
> http://lists.puremagic.com/mailman/listinfo/phobos

1 2 3
Next ›   Last »