You aren't getting what I mean.

Have you determined whether your process grows memory usage purely form the 
Django parts of your application?

In other words, if you ran up the application and hit a URL which doesn't run 
your algorithm, does it still grow in memory usage?

Make sure it isn't something else in your code.

Also, that you are using a thread to run stuff in immediately looks dodgy.

When you do a join() with a timeout, sure it returns, but it isn't going to 
kill the thread, it will keep running. You have to set some flag which the 
algorithm checks to periodically to see if it should exit. I can't see that you 
are doing that.

Graham

On 13/02/2015, at 9:58 PM, Paul Royik <[email protected]> wrote:

> Thank you for your response.
> 
> As I told you, I have integral calculator. In general it is a hard problem.
> When algoritm is executed, it goes through a list of integration rules. 
> Sometimes rules can be run infinitely and it is impossible to tell, whether 
> it is infinite execution. Like for integral sin(x)/(cos(x)+tan(x)) algo uses 
> a list of rules and each rule is followed by other rules etc.
> 
> So, I set a limit of time, using the following decorator:
> def time_limit(timeout):
>     def internal(function):
>         def internal2(*args, **kw):
>             class Calculator(threading.Thread):
>                 def __init__(self):
>                     threading.Thread.__init__(self)
>                     self.result = None
>                     self.error = None
> 
>                 def run(self):
>                     try:
>                         self.result = function(*args, **kw)
>                     except Exception as e:
>                         self.error = e
> 
>                 def _stop(self):
>                     if self.isAlive():
>                         threading.Thread._Thread__stop(self)
>             c = Calculator()
>             c.start()
>             c.join(timeout)
>             if c.isAlive():
>                 raise TimeoutException
>             if c.error:
>                 raise c.error
>             return c.result
>         return internal2
>     return internal
> 
> It works good. I usually set limit 150 seconds. But it appears that memory is 
> used faster than time. Even time reduction to 45 seconds doesn't work.
> So, I thought that maybe similar code can be written for memory management. 
> When memory is exceeded raise some Exception.
> Though, I can't find any working example.
> 
> Maybe you can help me?
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "modwsgi" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to [email protected].
> To post to this group, send email to [email protected].
> Visit this group at http://groups.google.com/group/modwsgi.
> For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"modwsgi" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/modwsgi.
For more options, visit https://groups.google.com/d/optout.

Reply via email to