On 08/03/2012 06:13 PM, Anthony wrote:
> When you said "worker", I assumed you were using the web2py Scheduler --
> is that the case? If so, you can put something like the following in the
> model or controller that does the import:
> 
> |
> ifrequest.global_settings.scheduler:
>     [dothe time-consuming import]
> |
> 
> If you're not using the Scheduler, what do you mean by "worker"?

I was referring of a module in applications/milo/modules that is used in
a applications/milo/models

When the import is done, the request object is not yet created in either
web2py server or shell or worker (web2py.py -K milo)

It gets created elsewhere after. Because after the shell is loaded i've
a request object.

Btw I've fixed my issue using a class like this:

class Tagger(object):
    tagger = None
    @classmethod
    def create(cls):
        if not cls.tagger:
            import nltk
            from nltk.corpus import brown
            brown_tagged = brown.tagged_sents()
            cls.tagger = nltk.UnigramTagger(brown_tagged)

    @classmethod
    def get(cls):
        if not cls.tagger:
            cls.create()
        return cls.tagger

When I call Tagger.get() the huge import is executed once only :)

Thanks anyway.
-- 
Vincenzo Ampolo
http://vincenzo-ampolo.net
http://goshawknest.wordpress.com

-- 



Reply via email to