Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 594439
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T15:57:13+00:00 2026-05-13T15:57:13+00:00

I am creating an IronPython engine more or less like so: var engine =

  • 0

I am creating an IronPython engine more or less like so:

var engine = IronPython.Hosting.Python.CreateEngine();                
var scope = engine.CreateScope();

// my implementation of System.IO.Stream
var stream = new ScriptOutputStream(engine);
engine.Runtime.IO.SetOutput(stream, Encoding.UTF8);
engine.Runtime.IO.SetErrorOutput(stream, Encoding.UTF8);
engine.Runtime.IO.SetInput(stream, Encoding.UTF8);

var script = engine.CreateScriptSourceFromString(source, SourceCodeKind.Statements);
script.Execute(scope);

The variable source is a string with following contents (python statements):

import code
code.interact(None, None, 
        {
            '__name__' :  '__console__', 
            '__doc__'  :   None, 
        })

The stream is being hosted on a windows form. When that form closes, I want the interpreter to quit. Obviously, I tried closing the stream in the Read method:

    /// <summary>
    /// Read from the _inputBuffer, block until a new line has been entered...
    /// </summary>
    public override int Read(byte[] buffer, int offset, int count)
    {

        if (_gui.IsDisposed)
        {
            return 0; // msdn says this indicates the stream is closed
        }

        while (_completedLines.Count < 1)
        {
            // wait for user to complete a line
            Application.DoEvents();
            Thread.Sleep(10);
        }
        var line = _completedLines.Dequeue();
        return line.Read(buffer, offset, count);
    }

The member variable _completedLines holds a queue of MemoryStream objects representing lines the user has entered so far. _gui is a reference to the windows form – when it is disposed, I somehow want the IronPython engine to stop executing code.interact().

Returnin 0 from the Read method does not work (Read is just called again). Raising one of the exceptions from the documentation of Read does not work either: It does stop execution of the interpreter, but the IDE breaks inside the Read method 🙁

I have also tried returning ^Z (0x1a) and ^D (0x04) in Read‘s buffer, as these are used on the console to quit the interpreter, but that doesn’t work at all…

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T15:57:14+00:00Added an answer on May 13, 2026 at 3:57 pm

    It took me a second look to figure out what you wanted, but this looks like a bug in IronPython. code.interact expects an EOFError to be raised from the raw_input builtin to signal that it’s time for the loop to end, but IronPython doesn’t do that – it just returns an empty string. This is IronPython issue #22140.

    You could try throwing an EndOfStreamException, which converts to EOFError. That might be enough to trick it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 440k
  • Answers 440k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Ok, I havent found a simple solution and no one… May 15, 2026 at 5:17 pm
  • Editorial Team
    Editorial Team added an answer In case others see this. What I did to solve… May 15, 2026 at 5:17 pm
  • Editorial Team
    Editorial Team added an answer -objectForKey: returns nil if the key doesn't exist in the… May 15, 2026 at 5:17 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.