In using ./manage.py shell to exercise some code, I've come across something I don't understand.
Python 2.6.6 (r266:84292, Sep 11 2012, 08:34:23)
[GCC 4.4.6 20120305 (Red Hat 4.4.6-4)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>> from multiprocessing import Process
>>> from django.core.management import call_command
>>> p = Process(target=call_command("processphoto", 1000))
Successfully populated photo "1000" (This is output from my processphoto command)
>>>
I never get the opportunity to do a p.start()
or set any other variables on the process. It appears to execute on instantation. When I try to use the code in my view, I don't appear to get multiple processes spawning at all, everything remains on the one core.
What am I doing wrong, or misunderstanding? I want to generate separate manage.py processphoto
commands in separate processes to fully utilize the multi-core server.
call_command(...)
calls the function. Instead, pass the function object, call_command
, and its arguments separately to Process
:
p = Process(target=call_command, args = ("processphoto", 1000))