I made a research and found no suspicious imports.
I give you contents of mathsite.timeout module for further research:
exceptions.py
class TimeoutException(Exception):
pass
manager.py
from mathsite.timeout.timeout import MyManager
import os
def get_manager():
sockpath = os.path.join(os.path.dirname(__file__),
'task-queue-manager.sock')
if True:
return
try:
m = MyManager(address=sockpath, authkey='abracadabra')
m.connect()
return m.Maths()
except:
return None
task-queue-manager.py
import os
from mathsite.timeout.timeout import MyManager
sockpath = os.path.join(os.path.dirname(__file__),
'task-queue-manager.sock')
try:
os.unlink(sockpath)
except OSError:
pass
m = MyManager(address=sockpath, authkey='abracadabra')
s = m.get_server()
s.serve_forever()
timeout.py
import multiprocessing
import os
import signal
from multiprocessing.managers import BaseManager
from mathsite.timeout.exceptions import TimeoutException
class RunableProcessing(multiprocessing.Process):
def __init__(self, func, *args, **kwargs):
self.queue = multiprocessing.Manager().Queue(maxsize=1)
args = (func,) + args
multiprocessing.Process.__init__(self, target=self.run_func,
args=args, kwargs=kwargs)
def run_func(self, func, *args, **kwargs):
try:
result = func(*args, **kwargs)
self.queue.put((True, result))
except Exception as e:
self.queue.put((False, e))
def done(self):
return self.queue.full()
def result(self):
return self.queue.get()
def timeout(seconds, function, *args, **kwargs):
proc = RunableProcessing(function, *args, **kwargs)
proc.start()
proc.join(seconds)
if proc.is_alive():
proc.terminate()
proc.join(1)
if proc.is_alive():
try:
os.kill(proc.pid, signal.SIGKILL)
except Exception:
pass
proc.join(1)
raise TimeoutException
success, result = proc.result()
if success:
return result
else:
raise result
class MathClass(object):
def run(self, seconds, func, *args, **kwargs):
return timeout(seconds, func, *args, **kwargs)
class MyManager(BaseManager):
pass
MyManager.register('Maths', MathClass)
utils.py
import time
import subprocess
from mathsite.timeout.exceptions import TimeoutException
class TimeLimit(object):
def __init__(self, timeout=250):
self.timeout = timeout
self.end = None
self.counter = 0
def check_timeout(self):
if self.end:
if time.time() > self.end:
raise TimeoutException
else:
self.start()
self.counter += 1
def start(self):
if not self.end:
self.end = time.time() + self.timeout
def command_with_timeout(cmd, timeout_sec):
result = subprocess.check_output(cmd+[str(timeout_sec)])
if result:
return result
else:
raise TimeoutException
If I understood you correctly, then I need to remove dependencies from
external libraries, but in these files there are dependencies only inside
package and from standard python libraries. I don't load anything else.
On Monday, March 2, 2015 at 1:03:59 PM UTC+2, Paul Royik wrote:
>
> Yes. It's mine.
>
> On Monday, March 2, 2015 at 11:46:16 AM UTC+2, Graham Dumpleton wrote:
>
> What is the external library?
>
> I am presuming that 'mathsite' is yours and do not see any evidence in the
> list of modules you gave me that it in turn imports some third party module
> wrapping an extension module linking in some third party library.
>
> Graham
>
> On 02/03/2015, at 8:34 PM, Paul Royik <[email protected]> wrote:
>
> What if extrnal library takes much memory?
>
> On Monday, March 2, 2015 at 11:33:48 AM UTC+2, Paul Royik wrote:
>
> OK.
> I will try.
>
> On Monday, March 2, 2015 at 2:26:40 AM UTC+2, Graham Dumpleton wrote:
>
> If I exclude your mathsite modules, on MacOS X at least, importing all the
> other modules under mod_wsgi only results in a process size under 12MB.
>
> What sort of data are your mathsite modules loading as part of the code,
> or preloading in some way from somewhere else. For them to take 30MB is
> quite a lot.
>
> Right now because you are preloading mathsite into the
> task-queue-manager.py file at global scope, that process itself is quite
> larger to begin with. At the least what you should do is organise the
> algorithm function being called under the task manager as a wrapper which
> only lazily imports the mathsite module when it is called.
>
> That is, mathsite would not be preloaded in task-queue-manager.py,
>
> ...
--
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.