Giter Site home page Giter Site logo

Comments (2)

Wintereise avatar Wintereise commented on June 21, 2024 1

Hi @madelson

Thank you for the insight, understood.

I'll close this.

from medallionshell.

madelson avatar madelson commented on June 21, 2024

Hi @Wintereise . While I suppose you can technically "re-start" a .NET process object by calling Start again it feels strange to me to do that since you are really just starting a completely new process. Calling Start again will blow away the std IO streams (as you are seeing) and could do weird things with subscribed events which makes code that uses this pattern prone to bugs.

MedallionShell takes the approach that processes are one-time events (Commands), e. g. associating each process with a Task which is not restartable.

Therefore, I think the best way to represent a process that may die with or without MedallionShell is to create an entirely new Command/Process object on each restart.

For example, if you want a process that auto-restarts on unexpected failure you could do something like this:

while (true)
{
    var command = ConfigureAndRunCommand(...)
         .RedirectTo(...);
    if ((await command.Task).Success) { break; }
}

In this case, we're taking advantage of a MedallionShell feature which makes sure all output has been written from redirection before allowing the Commands Task to finish. This makes sure that we won't hit thread-safety issues if the old and new process were being redirected to the same place.

If we want the ability to kill this loop ourselves, we can easily pass in a CancellationToken to Run using options.CancellationToken(...). That way, when cancellation is triggered it will (a) kill the process and (b) have the Command's task flip to the Canceled state, which will cause an OperationCanceledException to be thrown, exiting the loop.

from medallionshell.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.