[IronPython] Are two PythonEngine instances connected?

Dino Viehland dinov at exchange.microsoft.com
Mon Apr 17 16:57:56 CEST 2006


Yes, right now we unfortunately have some shared state between them.  We're not entirely certain where we'll land w/ this for V1 yet - whether we'll attempt to keep them separated entirely, or make it obvious (e.g. a static class) that there's only one engine available.  If we end up w/ just one then our isolation story would be app domain isolation.

If you've got feedback on which one is better for you (I'm guessing having them be independent) we'd love to hear it.

Do you want to help develop Dynamic languages on CLR?<http://members.microsoft.com/careers/search/details.aspx?JobID=6D4754DE-11F0-45DF-8B78-DC1B43134038> (http://members.microsoft.com/careers/search/details.aspx?JobID=6D4754DE-11F0-45DF-8B78-DC1B43134038)
________________________________
From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Kristof Wagemans
Sent: Sunday, April 16, 2006 6:02 AM
To: users at lists.ironpython.com
Subject: [IronPython] Are two PythonEngine instances connected?

I've created two PythonEngine instances and set the Stdout for each instance to its own custom stream class (PythonStream) to capture the output. This stream class takes a delegate to specify the function to receive the response.

    class Tester
    {
        public void Test()
        {
            PythonEngine pythonEngine1 = new PythonEngine();
            pythonEngine1.SetStdout(new PythonStream(ResponsePythonEngine1));

            Console.WriteLine("pythonEngine1.Execute(\"'p1'\") -> ");
            pythonEngine1.Execute("'p1'");
            Console.WriteLine("");

            PythonEngine pythonEngine2 = new PythonEngine();
            pythonEngine2.SetStdout(new PythonStream(ResponsePythonEngine2));

            Console.WriteLine("pythonEngine2.Execute(\"'p2'\") -> ");
            pythonEngine2.Execute("'p2'");
            Console.WriteLine("");

            Console.WriteLine("pythonEngine1.Execute(\"'p1'\") -> ");
            pythonEngine1.Execute("'p1'");
            Console.WriteLine("");

            Console.ReadLine();
        }

        void ResponsePythonEngine1(string text)
        {
            if (!string.IsNullOrEmpty(text.Trim()))
            {
                Console.WriteLine("  ResponsePythonEngine1 -> " + text);
            }
        }

        void ResponsePythonEngine2(string text)
        {
            if (!string.IsNullOrEmpty(text.Trim()))
            {
                Console.WriteLine("  ResponsePythonEngine2 -> " + text);
            }
        }
    }


After pythonEngine2 is created I receive the responses from commands executed on pythonEngine1 on the output of pythonEngine2.

pythonEngine1.Execute("'p1'") ->
  ResponsePythonEngine1 -> 'p1'

pythonEngine2.Execute("'p2'") ->
  ResponsePythonEngine2 -> 'p2'

pythonEngine1.Execute("'p1'") ->
  ResponsePythonEngine2 -> 'p1'


You can find my test application here:
http://users.telenet.be/kristof.wagemans/PythonEngineConnected.zip

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/ironpython-users/attachments/20060417/9c8d78b9/attachment.html>


More information about the Ironpython-users mailing list