Has anyone successfully got IronPython without problems in a web environment? I am facing some problems.
The first problem, I do not actually run any IronPython-specific scripts, I implement the Pygments library so that I can get the server syntax highlighting. The library contains about 20 files.
Besides the fact that the latest version of IronPython cannot compile scripts into DLLs (due to this problem ), I have this successfully just by copying all the files and dependencies to the bin folder.
The problem is that I went to see how my w3wp.exe process works when performing highlighting and noticed some problems with showstopper:
Even on an absolutely basic, empty Cassini website, highlighting select * from table code using SQL lexer causes a 10 MB jump every time it is executed (page refresh) ... I explicitly close and use LightweightScopes in one function call. It starts at about 30 MB and about 20 updates it at 150 MB or so.
In my real web application, using the SQL lexer (same code), my application pool increases by about 200 MB / s (literally, I kill it when it reaches about 1 GB) until it works w3wp or slows down my PC to crawl. This does not happen on an empty test site, and there is no problem in a console application with the same code. Other lexers, such as C #, do not cause a huge memory leak, but have the same effect of increasing the amount of memory each time the function is called.
This leads me to believe that this is a problem with the website, as the console application does not have any problems (although creating an instance of the runtime results in a 20 MB increase in memory).
I am using version 2.7 of IPY and version 1.4 of Pygments.
I don't have the exact code with me at the moment, but it looks something like this:
var options = something; options["LightweightScopes"] = ScriptRuntimeHelpers.True; // from another SO post, 'true' didn't seem to work var engine = Python.CreateEngine(options); // // set up search paths here... // dynamic scope = whatever; ScriptSource source = engine.CreateScriptSourceFromFile("myscript.py"); // Execute? Compile? It populates the scope at this point... source.Compile(scope); // execute (code, lexer name, style) // this is a python function I have that calls the Pygments code var highlighted = scope.generate_html("select * from table", "sql", "monokai"); engine.Shutdown(); return highlighted;
As I said, I copied the same code in: a) a console application, b) a completely new empty web application, c) my original web application. The console application does not leak memory, but web applications do.
I also executed this function with both my own Python ( python myscript.py ) and IPY ( ipy myscript.py ), and they had no memory leaks.
Is there any best practice that I am missing to get rid of runtime? I plan to run this in a shared environment, so a possible workaround to create an engine instance in a different application pool probably won't work for me (also, that a huge leak with 200 MB / s is a kind of showcase).
Currently, if someone doesn't have a miracle cure, I plan on abandoning my code and just go with a Javascript syntax shortcut. This is really unsuccessful because the Pigments are amazing ...