Skip to content

Exception in flask and mod_wsgi app #180

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
danic opened this issue Mar 9, 2016 · 8 comments
Closed

Exception in flask and mod_wsgi app #180

danic opened this issue Mar 9, 2016 · 8 comments

Comments

@danic
Copy link

danic commented Mar 9, 2016

Has anybody managed to successfully run a (non-trivial) Flask app under Apache mod_wsgi using pythonnet ? My app keeps throwing this exception:

"System.TypeInitializationException: The type initializer for 'System.Web.Script.Serialization.JavaScriptSerializer' threw an exception. ---> System.Configuration.ConfigurationErrorsException: Error Initializing the configuration system. ---> System.ArgumentException: The 'ExeConfigFilename' argument cannot be null"

as soon as it tries to use a clr object that deserializes some JSON. Full details here:

http://stackoverflow.com/questions/35872504/pythonnet-exception-the-execonfigfilename-argument-cannot-be-null

On this bug Mono added the mono_domain_set_config API to help with this situation. I don't see that method being called in the Mono code. Neither it seems to be called if I run the code in this other bug through gdb. However the code does not crash, as on the other hand I would expect as my version of Mono does have that bugfix. Still don't quite understand how that bug fix works though if it's not being called. Obviously missing something fairly fundamental here.
Maybe pythonnet PyNet_Init needs to explicitly call mono_domain_set_config ?

@danic
Copy link
Author

danic commented Mar 9, 2016

It does indeed seem that adding a call to mono_domain_set_config in PyNet_Init fixes the issue:

diff --git a/src/monoclr/pynetinit.c b/src/monoclr/pynetinit.c
index eaa1d9c..ed247f2 100644
--- a/src/monoclr/pynetinit.c
+++ b/src/monoclr/pynetinit.c
@@ -31,6 +31,7 @@ PyNet_Args* PyNet_Init(int ext) {
     pn_args->shutdown_name = "Python.Runtime:Shutdown()";

     pn_args->domain = mono_jit_init_version(MONO_DOMAIN, MONO_VERSION);
+    mono_domain_set_config(pn_args->domain, ".", "Python.Runtime.dll.config");

danic pushed a commit to danic/pythonnet that referenced this issue Mar 9, 2016
@danic
Copy link
Author

danic commented Mar 9, 2016

See #181. Travis build failing because it's using an ancient Mono 3.2.8 which does not even have the mono_domain_set_config fix (that was rolled out in 3.8.0). I'm on 4.2.2.

@den-run-ai
Copy link
Contributor

@danic see this doc how to update mono on travis ci:

https://docs.travis-ci.com/user/languages/csharp/

@danic
Copy link
Author

danic commented Mar 10, 2016

@denfromufa saw that thanks. Did try a couple of things on my fork by specifying mono versions but it doesn't work because Travis is using ancient Precise VMs. I did try the new Trusty image but the build hung out and failed. It's kind of irrelevant though as I know my fix works on both distros in fact as I have both a Precise box and a Trusty AWS instance both with Mono 4.2.2. So I'll leave it at that for the time being.

@den-run-ai
Copy link
Contributor

@danic maybe it is possible to download latest mono binaries (4.2.2) instead of compiling on build machine? it probably time outs before it builds due to constrained resources.

@danic
Copy link
Author

danic commented Mar 11, 2016

After a few disagreements with Travis I finally managed to persuade it to build it. It works now.

danic pushed a commit to danic/pythonnet that referenced this issue Mar 14, 2016
danic pushed a commit to danic/pythonnet that referenced this issue Mar 14, 2016
tonyroberts added a commit that referenced this issue Mar 15, 2016
tonyroberts added a commit that referenced this issue Mar 15, 2016
tonyroberts added a commit that referenced this issue Mar 15, 2016
@tonyroberts tonyroberts reopened this Mar 15, 2016
@tonyroberts
Copy link
Contributor

I've re-opened this as the PR was against the wrong branch. Please submit a new PR against the develop branch.

tonyroberts pushed a commit to tonyroberts/pythonnet that referenced this issue Mar 15, 2016
tonyroberts pushed a commit to tonyroberts/pythonnet that referenced this issue Mar 15, 2016
Update travis CI build to use latest mono and add a call to
mono_domain_set_config to solve problems using pythonnet with
mod_wsgi.
tonyroberts pushed a commit to tonyroberts/pythonnet that referenced this issue Mar 15, 2016
Update travis CI build to use latest mono and add a call to mono_domain_set_config to solve problems using pythonnet with mod_wsgi.
@tonyroberts
Copy link
Contributor

Done - see PR #189

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

No branches or pull requests

3 participants