Jonathan,

I misunderstood your problem. You should not spawn threads from a
web2py app. This is not just because the current routing mechanism
does not support it. This is a very general with all web applications
because threads are managed by the web server which starts/stops and
kills them. If your thread spawns a new thread and the parent is
killed by the web server you may end up with a memory leak.

Please explain what you are trying to achieve, perhaps show us some
code, and I am sure there is another way.

Massimo

On Sep 16, 2:26 pm, "Jonathan Z." <[email protected]> wrote:
> I'm kicking off a threaded process.  As part of the "run" method, I'm
> calling: env("application", import_models=True) in order to work with
> the web2py environment inside the context of my thread.  As a result,
> models are parsed and the following exception is raised:
>
> Traceback (most recent call last):
>   File ".../web2py/gluon/restricted.py", line 188, in restricted
>     exec ccode in environment
>   File "applications/app/models/db.py", line 32, in <module>
>     auth = Auth(globals(), db)
>   File ".../web2py/gluon/tools.py", line 804, in __init__
>     self.settings.login_url = self.url('user', args='login')
>   File ".../web2py/gluon/tools.py", line 762, in url
>     f=f, args=args, vars=vars)
>   File ".../web2py/gluon/html.py", line 228, in _URL
>     return URL(*args, **kwargs)
>   File ".../web2py/gluon/html.py", line 206, in URL
>     return XML(rewrite.filter_out(url, env))
>   File ".../web2py/gluon/rewrite.py", line 183, in filter_out
>     if thread.routes.routes_out:
> AttributeError: 'thread._local' object has no attribute 'routes'
>
> As soon as URLs are parsed during Auth initialization, the thread hits
> a case where an invalid "routes" attribute is dereferenced within
> rewrite.py.  My threaded code was working until the following change
> was rolled into 1.84.x: "moved DAL and routes to thread.local"

Reply via email to