yet another confusion with multiprocessing error, 'module' object has no attribute 'f'
I know this has been answered before, but it seems that executing the script directly "python filename.py" does not work. I have Python 2.6.2 on SuSE Linux.
Code:
#!/usr/bin/python
# -*- coding: utf-8 -*-
from multiprocessing import Pool
p = Pool(1)
def f(x):
return x*x
p.map(f, [1, 2, 3])
Command line:
> python example.py
Process PoolWorker-1:
Traceback (most recent call last):
File "/usr/lib/python2.6/multiprocessing/process.py", line 231, in _bootstrap
self.run()
File "/usr/lib/python2.6/multiprocessing/process.py", line 88, in run
self._target(*self._args, **self._kwargs)
File "/usr/lib/python2.6/multiprocessing/pool.py", line 57, in worker
task = get()
File "/usr/lib/python2.6/multiprocessing/queues.py", line 339, in get
return recv()
AttributeError: 'module' object has no attribute 'f'
python multiprocessing
add a comment |
I know this has been answered before, but it seems that executing the script directly "python filename.py" does not work. I have Python 2.6.2 on SuSE Linux.
Code:
#!/usr/bin/python
# -*- coding: utf-8 -*-
from multiprocessing import Pool
p = Pool(1)
def f(x):
return x*x
p.map(f, [1, 2, 3])
Command line:
> python example.py
Process PoolWorker-1:
Traceback (most recent call last):
File "/usr/lib/python2.6/multiprocessing/process.py", line 231, in _bootstrap
self.run()
File "/usr/lib/python2.6/multiprocessing/process.py", line 88, in run
self._target(*self._args, **self._kwargs)
File "/usr/lib/python2.6/multiprocessing/pool.py", line 57, in worker
task = get()
File "/usr/lib/python2.6/multiprocessing/queues.py", line 339, in get
return recv()
AttributeError: 'module' object has no attribute 'f'
python multiprocessing
1
possible duplicate of Using python multiprocessing Pool in the terminal and in code moudles for Django or Flask
– jb.
Aug 10 '14 at 13:00
@jb. that post is much later than this one, this was 2010, that one is 2013
– gatoatigrado
Aug 18 '14 at 23:26
2
Age is irrevelant there is consensus on meta that question with better answer should be chosen, and another one has IMO better answer.
– jb.
Aug 19 '14 at 7:52
add a comment |
I know this has been answered before, but it seems that executing the script directly "python filename.py" does not work. I have Python 2.6.2 on SuSE Linux.
Code:
#!/usr/bin/python
# -*- coding: utf-8 -*-
from multiprocessing import Pool
p = Pool(1)
def f(x):
return x*x
p.map(f, [1, 2, 3])
Command line:
> python example.py
Process PoolWorker-1:
Traceback (most recent call last):
File "/usr/lib/python2.6/multiprocessing/process.py", line 231, in _bootstrap
self.run()
File "/usr/lib/python2.6/multiprocessing/process.py", line 88, in run
self._target(*self._args, **self._kwargs)
File "/usr/lib/python2.6/multiprocessing/pool.py", line 57, in worker
task = get()
File "/usr/lib/python2.6/multiprocessing/queues.py", line 339, in get
return recv()
AttributeError: 'module' object has no attribute 'f'
python multiprocessing
I know this has been answered before, but it seems that executing the script directly "python filename.py" does not work. I have Python 2.6.2 on SuSE Linux.
Code:
#!/usr/bin/python
# -*- coding: utf-8 -*-
from multiprocessing import Pool
p = Pool(1)
def f(x):
return x*x
p.map(f, [1, 2, 3])
Command line:
> python example.py
Process PoolWorker-1:
Traceback (most recent call last):
File "/usr/lib/python2.6/multiprocessing/process.py", line 231, in _bootstrap
self.run()
File "/usr/lib/python2.6/multiprocessing/process.py", line 88, in run
self._target(*self._args, **self._kwargs)
File "/usr/lib/python2.6/multiprocessing/pool.py", line 57, in worker
task = get()
File "/usr/lib/python2.6/multiprocessing/queues.py", line 339, in get
return recv()
AttributeError: 'module' object has no attribute 'f'
python multiprocessing
python multiprocessing
asked May 6 '10 at 17:08
gatoatigradogatoatigrado
8,688763127
8,688763127
1
possible duplicate of Using python multiprocessing Pool in the terminal and in code moudles for Django or Flask
– jb.
Aug 10 '14 at 13:00
@jb. that post is much later than this one, this was 2010, that one is 2013
– gatoatigrado
Aug 18 '14 at 23:26
2
Age is irrevelant there is consensus on meta that question with better answer should be chosen, and another one has IMO better answer.
– jb.
Aug 19 '14 at 7:52
add a comment |
1
possible duplicate of Using python multiprocessing Pool in the terminal and in code moudles for Django or Flask
– jb.
Aug 10 '14 at 13:00
@jb. that post is much later than this one, this was 2010, that one is 2013
– gatoatigrado
Aug 18 '14 at 23:26
2
Age is irrevelant there is consensus on meta that question with better answer should be chosen, and another one has IMO better answer.
– jb.
Aug 19 '14 at 7:52
1
1
possible duplicate of Using python multiprocessing Pool in the terminal and in code moudles for Django or Flask
– jb.
Aug 10 '14 at 13:00
possible duplicate of Using python multiprocessing Pool in the terminal and in code moudles for Django or Flask
– jb.
Aug 10 '14 at 13:00
@jb. that post is much later than this one, this was 2010, that one is 2013
– gatoatigrado
Aug 18 '14 at 23:26
@jb. that post is much later than this one, this was 2010, that one is 2013
– gatoatigrado
Aug 18 '14 at 23:26
2
2
Age is irrevelant there is consensus on meta that question with better answer should be chosen, and another one has IMO better answer.
– jb.
Aug 19 '14 at 7:52
Age is irrevelant there is consensus on meta that question with better answer should be chosen, and another one has IMO better answer.
– jb.
Aug 19 '14 at 7:52
add a comment |
5 Answers
5
active
oldest
votes
Restructure your code so that the f()
function is defined before you create instance of Pool. Otherwise the worker cannot see your function.
#!/usr/bin/python
# -*- coding: utf-8 -*-
from multiprocessing import Pool
def f(x):
return x*x
p = Pool(1)
p.map(f, [1, 2, 3])
7
awesome, thank you so much!! What cryptic usage!
– gatoatigrado
May 7 '10 at 0:21
1
NOTE: A few years later, I've started writing an imap alternative [ github.com/gatoatigrado/vimap ], which makes this mistake more difficult (and makes it clear when threads are forked).
– gatoatigrado
Jun 13 '13 at 22:29
1
@Bartosz, Do you have any idea why this is not a problem in ipython notebooks?
– Framester
Oct 7 '14 at 9:33
@Framester: Odds are, ipython notebooks are using a "spawn" like approach to multiprocessing, rather than a "fork" based approach. The spawn based approach is to either launch a fresh process and import the main module (but not as__main__
, to prevent it doing theif __name__ == '__main__
:` stuff), or pickle interpreter state to transmit to child.fork
semantics are faster, but only work on a single machine, and not on Windows. Spawn semantics can be made to work anywhere (e.g. Windows w/ofork
), and can work on a cluster, and ipython notebooks are intended for multimachine cases.
– ShadowRanger
Apr 18 '16 at 17:16
add a comment |
This one works:
#!/usr/bin/python
# -*- coding: utf-8 -*-
from multiprocessing import Pool
def f(x):
return x*x
if __name__ == "__main__":
p = Pool(1)
p.map(f, [1, 2, 3])
I'm not 100% sure why your code does not work, but I guess the reason is that child processes launched by the multiprocessing
module try to import the main module (to have access to the methods you defined), and the if __name__ == "__main__"
stanza is required not to execute the initialization code where you set up your pool.
If one has to run such code through an interpreter on Windows is there any work around? This is the situation I'm confronted with doing some Python-Fu programming from the Gimp Python Console plugin.
– jxramos
Mar 12 '15 at 2:40
This one did not work for me
– Dang Manh Truong
Nov 4 '17 at 11:07
@Tamás, it does not work for me either,from multiprocessing import Pool
,ImportError: cannot import name Pool
– Houy Narun
May 29 '18 at 6:31
add a comment |
One possibility is that your python file has the same name as a module:
- test.py
- test/
- __init__.py
in pickle.py, you have the error coming from:
def find_class(self, module, name):
# Subclasses may override this
__import__(module)
mod = sys.modules[module] # <- here mod will reference your test/__init__.py
klass = getattr(mod, name)
return klass
add a comment |
The problem I had was solved by using if __name__ == "__main__"
as pointed out by Tamás; in Eclipse for Windows the examples do not work under the interpreter.
This is explained in
http://docs.python.org/2/library/multiprocessing
add a comment |
This comes from the fact that with p = Pool(1)
the main process forks processes (threads vs processes) before it creates the function f. As stated in Bartosz answer the spawned processes do not have access to the new function.
def f1(x):
...
p = Pool(1) # p is spawned and is now an independent process, knows f1
def f(x): # p doesn't not share this object
...
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f2782961%2fyet-another-confusion-with-multiprocessing-error-module-object-has-no-attribu%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
5 Answers
5
active
oldest
votes
5 Answers
5
active
oldest
votes
active
oldest
votes
active
oldest
votes
Restructure your code so that the f()
function is defined before you create instance of Pool. Otherwise the worker cannot see your function.
#!/usr/bin/python
# -*- coding: utf-8 -*-
from multiprocessing import Pool
def f(x):
return x*x
p = Pool(1)
p.map(f, [1, 2, 3])
7
awesome, thank you so much!! What cryptic usage!
– gatoatigrado
May 7 '10 at 0:21
1
NOTE: A few years later, I've started writing an imap alternative [ github.com/gatoatigrado/vimap ], which makes this mistake more difficult (and makes it clear when threads are forked).
– gatoatigrado
Jun 13 '13 at 22:29
1
@Bartosz, Do you have any idea why this is not a problem in ipython notebooks?
– Framester
Oct 7 '14 at 9:33
@Framester: Odds are, ipython notebooks are using a "spawn" like approach to multiprocessing, rather than a "fork" based approach. The spawn based approach is to either launch a fresh process and import the main module (but not as__main__
, to prevent it doing theif __name__ == '__main__
:` stuff), or pickle interpreter state to transmit to child.fork
semantics are faster, but only work on a single machine, and not on Windows. Spawn semantics can be made to work anywhere (e.g. Windows w/ofork
), and can work on a cluster, and ipython notebooks are intended for multimachine cases.
– ShadowRanger
Apr 18 '16 at 17:16
add a comment |
Restructure your code so that the f()
function is defined before you create instance of Pool. Otherwise the worker cannot see your function.
#!/usr/bin/python
# -*- coding: utf-8 -*-
from multiprocessing import Pool
def f(x):
return x*x
p = Pool(1)
p.map(f, [1, 2, 3])
7
awesome, thank you so much!! What cryptic usage!
– gatoatigrado
May 7 '10 at 0:21
1
NOTE: A few years later, I've started writing an imap alternative [ github.com/gatoatigrado/vimap ], which makes this mistake more difficult (and makes it clear when threads are forked).
– gatoatigrado
Jun 13 '13 at 22:29
1
@Bartosz, Do you have any idea why this is not a problem in ipython notebooks?
– Framester
Oct 7 '14 at 9:33
@Framester: Odds are, ipython notebooks are using a "spawn" like approach to multiprocessing, rather than a "fork" based approach. The spawn based approach is to either launch a fresh process and import the main module (but not as__main__
, to prevent it doing theif __name__ == '__main__
:` stuff), or pickle interpreter state to transmit to child.fork
semantics are faster, but only work on a single machine, and not on Windows. Spawn semantics can be made to work anywhere (e.g. Windows w/ofork
), and can work on a cluster, and ipython notebooks are intended for multimachine cases.
– ShadowRanger
Apr 18 '16 at 17:16
add a comment |
Restructure your code so that the f()
function is defined before you create instance of Pool. Otherwise the worker cannot see your function.
#!/usr/bin/python
# -*- coding: utf-8 -*-
from multiprocessing import Pool
def f(x):
return x*x
p = Pool(1)
p.map(f, [1, 2, 3])
Restructure your code so that the f()
function is defined before you create instance of Pool. Otherwise the worker cannot see your function.
#!/usr/bin/python
# -*- coding: utf-8 -*-
from multiprocessing import Pool
def f(x):
return x*x
p = Pool(1)
p.map(f, [1, 2, 3])
answered May 6 '10 at 17:15
BartoszBartosz
4,69522115
4,69522115
7
awesome, thank you so much!! What cryptic usage!
– gatoatigrado
May 7 '10 at 0:21
1
NOTE: A few years later, I've started writing an imap alternative [ github.com/gatoatigrado/vimap ], which makes this mistake more difficult (and makes it clear when threads are forked).
– gatoatigrado
Jun 13 '13 at 22:29
1
@Bartosz, Do you have any idea why this is not a problem in ipython notebooks?
– Framester
Oct 7 '14 at 9:33
@Framester: Odds are, ipython notebooks are using a "spawn" like approach to multiprocessing, rather than a "fork" based approach. The spawn based approach is to either launch a fresh process and import the main module (but not as__main__
, to prevent it doing theif __name__ == '__main__
:` stuff), or pickle interpreter state to transmit to child.fork
semantics are faster, but only work on a single machine, and not on Windows. Spawn semantics can be made to work anywhere (e.g. Windows w/ofork
), and can work on a cluster, and ipython notebooks are intended for multimachine cases.
– ShadowRanger
Apr 18 '16 at 17:16
add a comment |
7
awesome, thank you so much!! What cryptic usage!
– gatoatigrado
May 7 '10 at 0:21
1
NOTE: A few years later, I've started writing an imap alternative [ github.com/gatoatigrado/vimap ], which makes this mistake more difficult (and makes it clear when threads are forked).
– gatoatigrado
Jun 13 '13 at 22:29
1
@Bartosz, Do you have any idea why this is not a problem in ipython notebooks?
– Framester
Oct 7 '14 at 9:33
@Framester: Odds are, ipython notebooks are using a "spawn" like approach to multiprocessing, rather than a "fork" based approach. The spawn based approach is to either launch a fresh process and import the main module (but not as__main__
, to prevent it doing theif __name__ == '__main__
:` stuff), or pickle interpreter state to transmit to child.fork
semantics are faster, but only work on a single machine, and not on Windows. Spawn semantics can be made to work anywhere (e.g. Windows w/ofork
), and can work on a cluster, and ipython notebooks are intended for multimachine cases.
– ShadowRanger
Apr 18 '16 at 17:16
7
7
awesome, thank you so much!! What cryptic usage!
– gatoatigrado
May 7 '10 at 0:21
awesome, thank you so much!! What cryptic usage!
– gatoatigrado
May 7 '10 at 0:21
1
1
NOTE: A few years later, I've started writing an imap alternative [ github.com/gatoatigrado/vimap ], which makes this mistake more difficult (and makes it clear when threads are forked).
– gatoatigrado
Jun 13 '13 at 22:29
NOTE: A few years later, I've started writing an imap alternative [ github.com/gatoatigrado/vimap ], which makes this mistake more difficult (and makes it clear when threads are forked).
– gatoatigrado
Jun 13 '13 at 22:29
1
1
@Bartosz, Do you have any idea why this is not a problem in ipython notebooks?
– Framester
Oct 7 '14 at 9:33
@Bartosz, Do you have any idea why this is not a problem in ipython notebooks?
– Framester
Oct 7 '14 at 9:33
@Framester: Odds are, ipython notebooks are using a "spawn" like approach to multiprocessing, rather than a "fork" based approach. The spawn based approach is to either launch a fresh process and import the main module (but not as
__main__
, to prevent it doing the if __name__ == '__main__
:` stuff), or pickle interpreter state to transmit to child. fork
semantics are faster, but only work on a single machine, and not on Windows. Spawn semantics can be made to work anywhere (e.g. Windows w/o fork
), and can work on a cluster, and ipython notebooks are intended for multimachine cases.– ShadowRanger
Apr 18 '16 at 17:16
@Framester: Odds are, ipython notebooks are using a "spawn" like approach to multiprocessing, rather than a "fork" based approach. The spawn based approach is to either launch a fresh process and import the main module (but not as
__main__
, to prevent it doing the if __name__ == '__main__
:` stuff), or pickle interpreter state to transmit to child. fork
semantics are faster, but only work on a single machine, and not on Windows. Spawn semantics can be made to work anywhere (e.g. Windows w/o fork
), and can work on a cluster, and ipython notebooks are intended for multimachine cases.– ShadowRanger
Apr 18 '16 at 17:16
add a comment |
This one works:
#!/usr/bin/python
# -*- coding: utf-8 -*-
from multiprocessing import Pool
def f(x):
return x*x
if __name__ == "__main__":
p = Pool(1)
p.map(f, [1, 2, 3])
I'm not 100% sure why your code does not work, but I guess the reason is that child processes launched by the multiprocessing
module try to import the main module (to have access to the methods you defined), and the if __name__ == "__main__"
stanza is required not to execute the initialization code where you set up your pool.
If one has to run such code through an interpreter on Windows is there any work around? This is the situation I'm confronted with doing some Python-Fu programming from the Gimp Python Console plugin.
– jxramos
Mar 12 '15 at 2:40
This one did not work for me
– Dang Manh Truong
Nov 4 '17 at 11:07
@Tamás, it does not work for me either,from multiprocessing import Pool
,ImportError: cannot import name Pool
– Houy Narun
May 29 '18 at 6:31
add a comment |
This one works:
#!/usr/bin/python
# -*- coding: utf-8 -*-
from multiprocessing import Pool
def f(x):
return x*x
if __name__ == "__main__":
p = Pool(1)
p.map(f, [1, 2, 3])
I'm not 100% sure why your code does not work, but I guess the reason is that child processes launched by the multiprocessing
module try to import the main module (to have access to the methods you defined), and the if __name__ == "__main__"
stanza is required not to execute the initialization code where you set up your pool.
If one has to run such code through an interpreter on Windows is there any work around? This is the situation I'm confronted with doing some Python-Fu programming from the Gimp Python Console plugin.
– jxramos
Mar 12 '15 at 2:40
This one did not work for me
– Dang Manh Truong
Nov 4 '17 at 11:07
@Tamás, it does not work for me either,from multiprocessing import Pool
,ImportError: cannot import name Pool
– Houy Narun
May 29 '18 at 6:31
add a comment |
This one works:
#!/usr/bin/python
# -*- coding: utf-8 -*-
from multiprocessing import Pool
def f(x):
return x*x
if __name__ == "__main__":
p = Pool(1)
p.map(f, [1, 2, 3])
I'm not 100% sure why your code does not work, but I guess the reason is that child processes launched by the multiprocessing
module try to import the main module (to have access to the methods you defined), and the if __name__ == "__main__"
stanza is required not to execute the initialization code where you set up your pool.
This one works:
#!/usr/bin/python
# -*- coding: utf-8 -*-
from multiprocessing import Pool
def f(x):
return x*x
if __name__ == "__main__":
p = Pool(1)
p.map(f, [1, 2, 3])
I'm not 100% sure why your code does not work, but I guess the reason is that child processes launched by the multiprocessing
module try to import the main module (to have access to the methods you defined), and the if __name__ == "__main__"
stanza is required not to execute the initialization code where you set up your pool.
answered May 6 '10 at 17:15
TamásTamás
37.9k882109
37.9k882109
If one has to run such code through an interpreter on Windows is there any work around? This is the situation I'm confronted with doing some Python-Fu programming from the Gimp Python Console plugin.
– jxramos
Mar 12 '15 at 2:40
This one did not work for me
– Dang Manh Truong
Nov 4 '17 at 11:07
@Tamás, it does not work for me either,from multiprocessing import Pool
,ImportError: cannot import name Pool
– Houy Narun
May 29 '18 at 6:31
add a comment |
If one has to run such code through an interpreter on Windows is there any work around? This is the situation I'm confronted with doing some Python-Fu programming from the Gimp Python Console plugin.
– jxramos
Mar 12 '15 at 2:40
This one did not work for me
– Dang Manh Truong
Nov 4 '17 at 11:07
@Tamás, it does not work for me either,from multiprocessing import Pool
,ImportError: cannot import name Pool
– Houy Narun
May 29 '18 at 6:31
If one has to run such code through an interpreter on Windows is there any work around? This is the situation I'm confronted with doing some Python-Fu programming from the Gimp Python Console plugin.
– jxramos
Mar 12 '15 at 2:40
If one has to run such code through an interpreter on Windows is there any work around? This is the situation I'm confronted with doing some Python-Fu programming from the Gimp Python Console plugin.
– jxramos
Mar 12 '15 at 2:40
This one did not work for me
– Dang Manh Truong
Nov 4 '17 at 11:07
This one did not work for me
– Dang Manh Truong
Nov 4 '17 at 11:07
@Tamás, it does not work for me either,
from multiprocessing import Pool
, ImportError: cannot import name Pool
– Houy Narun
May 29 '18 at 6:31
@Tamás, it does not work for me either,
from multiprocessing import Pool
, ImportError: cannot import name Pool
– Houy Narun
May 29 '18 at 6:31
add a comment |
One possibility is that your python file has the same name as a module:
- test.py
- test/
- __init__.py
in pickle.py, you have the error coming from:
def find_class(self, module, name):
# Subclasses may override this
__import__(module)
mod = sys.modules[module] # <- here mod will reference your test/__init__.py
klass = getattr(mod, name)
return klass
add a comment |
One possibility is that your python file has the same name as a module:
- test.py
- test/
- __init__.py
in pickle.py, you have the error coming from:
def find_class(self, module, name):
# Subclasses may override this
__import__(module)
mod = sys.modules[module] # <- here mod will reference your test/__init__.py
klass = getattr(mod, name)
return klass
add a comment |
One possibility is that your python file has the same name as a module:
- test.py
- test/
- __init__.py
in pickle.py, you have the error coming from:
def find_class(self, module, name):
# Subclasses may override this
__import__(module)
mod = sys.modules[module] # <- here mod will reference your test/__init__.py
klass = getattr(mod, name)
return klass
One possibility is that your python file has the same name as a module:
- test.py
- test/
- __init__.py
in pickle.py, you have the error coming from:
def find_class(self, module, name):
# Subclasses may override this
__import__(module)
mod = sys.modules[module] # <- here mod will reference your test/__init__.py
klass = getattr(mod, name)
return klass
answered Oct 13 '12 at 6:42
user1143523user1143523
443
443
add a comment |
add a comment |
The problem I had was solved by using if __name__ == "__main__"
as pointed out by Tamás; in Eclipse for Windows the examples do not work under the interpreter.
This is explained in
http://docs.python.org/2/library/multiprocessing
add a comment |
The problem I had was solved by using if __name__ == "__main__"
as pointed out by Tamás; in Eclipse for Windows the examples do not work under the interpreter.
This is explained in
http://docs.python.org/2/library/multiprocessing
add a comment |
The problem I had was solved by using if __name__ == "__main__"
as pointed out by Tamás; in Eclipse for Windows the examples do not work under the interpreter.
This is explained in
http://docs.python.org/2/library/multiprocessing
The problem I had was solved by using if __name__ == "__main__"
as pointed out by Tamás; in Eclipse for Windows the examples do not work under the interpreter.
This is explained in
http://docs.python.org/2/library/multiprocessing
answered Mar 30 '13 at 11:09
user2226924user2226924
16625
16625
add a comment |
add a comment |
This comes from the fact that with p = Pool(1)
the main process forks processes (threads vs processes) before it creates the function f. As stated in Bartosz answer the spawned processes do not have access to the new function.
def f1(x):
...
p = Pool(1) # p is spawned and is now an independent process, knows f1
def f(x): # p doesn't not share this object
...
add a comment |
This comes from the fact that with p = Pool(1)
the main process forks processes (threads vs processes) before it creates the function f. As stated in Bartosz answer the spawned processes do not have access to the new function.
def f1(x):
...
p = Pool(1) # p is spawned and is now an independent process, knows f1
def f(x): # p doesn't not share this object
...
add a comment |
This comes from the fact that with p = Pool(1)
the main process forks processes (threads vs processes) before it creates the function f. As stated in Bartosz answer the spawned processes do not have access to the new function.
def f1(x):
...
p = Pool(1) # p is spawned and is now an independent process, knows f1
def f(x): # p doesn't not share this object
...
This comes from the fact that with p = Pool(1)
the main process forks processes (threads vs processes) before it creates the function f. As stated in Bartosz answer the spawned processes do not have access to the new function.
def f1(x):
...
p = Pool(1) # p is spawned and is now an independent process, knows f1
def f(x): # p doesn't not share this object
...
answered Nov 14 '18 at 1:24
yosemite_kyosemite_k
890420
890420
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f2782961%2fyet-another-confusion-with-multiprocessing-error-module-object-has-no-attribu%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
possible duplicate of Using python multiprocessing Pool in the terminal and in code moudles for Django or Flask
– jb.
Aug 10 '14 at 13:00
@jb. that post is much later than this one, this was 2010, that one is 2013
– gatoatigrado
Aug 18 '14 at 23:26
2
Age is irrevelant there is consensus on meta that question with better answer should be chosen, and another one has IMO better answer.
– jb.
Aug 19 '14 at 7:52