#22 new
Paul J. Davis

JS_NewRuntime failures

Reported by Paul J. Davis | June 26th, 2009 @ 07:50 PM | in Version 0.1.0

Investigating [#21] 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.

Comments and changes to this ticket

  • evan2m

    evan2m May 13th, 2011 @ 05:12 PM

    • 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.

  • Paul J. Davis

    Paul J. Davis May 13th, 2011 @ 05:28 PM

    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.

  • evan2m

    evan2m May 13th, 2011 @ 06:19 PM

    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.

  • Chris

    Chris November 8th, 2013 @ 02:32 PM

    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.

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.

New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile ยป

Python/JavaScript bridge module, making use of Mozilla's spidermonkey JavaScript implementation. Allows implementation of JavaScript classes, objects and functions in Python, and evaluation and calling of JavaScript scripts and functions respectively. Borrows heavily from Claes Jacobssen's Javascript Perl module, in turn based on Mozilla's 'PerlConnect' Perl binding.

People watching this ticket

Pages