Skip to content
This repository has been archived by the owner on Sep 14, 2018. It is now read-only.

runtimes in a multi threaded environment #1173

Open
lysander12 opened this issue Feb 26, 2015 · 4 comments
Open

runtimes in a multi threaded environment #1173

lysander12 opened this issue Feb 26, 2015 · 4 comments

Comments

@lysander12
Copy link

Hi,
We are using IronPython every day and we can solve every job with it.
However we would like to use unlimited number of IronPython runtimes in an application now and preload some runtimes on starting to be faster later.

I made a little demo for the bug we have found.
The traceback import is the most important part of the code.
Maybe the traceback module is made for CPython where I cannot image such a scenario but in IronPython it is possible to use multiple runtimes in an application.

The demo can result various misterious crashes.
The goal would be that it could run on a multi core PC.
Sometimes a Thread.Sleep(400) between the thread start methods helps sometimes does not.
Sometimes the bug appears only after a PC restart.

    private void Button_Click(object sender, RoutedEventArgs e)
    {
        Thread t1 = new Thread(MakeRuntime);
        Thread t2 = new Thread(MakeRuntime);
        t1.Start();
        t2.Start();

    }
    void MakeRuntime() {
        try
        {
            Dictionary<string, object> options = new Dictionary<string, object>();
            options.Add("Debug", true);
            ScriptRuntime runtime = Python.CreateRuntime(options);
            ScriptEngine engine = runtime.GetEngine("py");

            List<string> paths = new List<string>();
            paths.Add(@"C:\Program Files (x86)\IronPython 2.7\Lib\");
            engine.SetSearchPaths(paths);
            ScriptScope scope = engine.CreateScope();
            engine.Execute("import sys;import traceback;", scope);
        }
        catch (Exception ex) {
            MessageBox.Show(ex.ToString());
        }
    }
}

Best Regards
David Fulop

@paweljasinski
Copy link
Contributor

here are a couple of stack traces generated from slightly modified (no gui) code.

@jdhardy
Copy link
Member

jdhardy commented Feb 28, 2015

Weakref seems like the common thread (ahem) in this case. There must be a synchronization issue in the weakref code, and I think there might be a couple of other open issues that have a similar problem.

@jdhardy
Copy link
Member

jdhardy commented Mar 1, 2015

@jdhardy
Copy link
Member

jdhardy commented Nov 15, 2015

This is probably related to #1187.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants