Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

JS_NewRuntime failures

#22

Investigating [#21 segfault/bus error in loop] I found that creating Runtimes ends up causing JS_NewRuntime() to start returning NULL. I'm not sure on the reasoning for this, but I don't think its anything that I'm doing. I've been pondering moving towards pushing the Runtime object internally so that clients never access it directly. There'd be exactly one JSRuntime* per Python process and all contexts would use that runtime. This would allow us to avoid having to pass a runtime around to create contexts etc.

For reference, to reproduce:

>>> import spidermonkey
>>> for i in range(1000):
...     rt = spidermonkey.Runtime()
... 
Traceback (most recent call last):
  File "<stdin>", line 2, in <module>
spidermonkey.JSError: Failed to allocate new JSRuntime.

Reported by Paul J. Davis · June 26th, 2009 @ 07:50 PM

State: new
Milestone: Version 0.1.0
Assigned to: Paul J. Davis Paul J. Davis

Activity

  1. evan2m
    evan2m
    • Milestone order changed from 0 to 0

    Anyone have ideas of how to workaround this problem? My long-running processes that create Runtime instances are dying with this error.

    I don't see anyway to explicitly free Runtime instances or share them between contexts.

    Paul's idea to privately manage the Runtime from within the class sounds like the right approach since there is no public API for Runtime anyway (except new_context).

    My context wrapper class works like this:

        def __init__(self):
            """ Create a JS context and add in our functions """
            rt = Runtime()
            self.ctx = rt.new_context()
    

    And errors on the rt = Runtime() line.

    May 13th, 2011 @ 05:12 PM

  2. Paul J. Davis
    Paul J. Davis

    Beyond sharing one runtime for the entire process there's not much I ever figured out on this. I'm not entirely certain on the best route other than to make the Runtime a process global.

    To free a runtime you just need to let it get garbage collected like any other python object.

    May 13th, 2011 @ 05:28 PM

  3. evan2m
    evan2m

    Thanks for the quick reply.

    I was able to workaround the problem by instantiating the Runtime at the module level rather than creating one for every instance of my wrapper class.

    May 13th, 2011 @ 06:19 PM

  4. Chris
    Chris

    I would be very interested in a python-spidermonkey version with Runtime as a process global. I'm using web2py which doesn't give direct thread control, so I have no way to figure out when the Runtime is garbage collected.

    November 8th, 2013 @ 02:32 PM

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.