Simple multiprocessing code, doesn't call callbackCalling a function of a module by using its name (a string)How should I unit test threaded code?Calling an external command in PythonIs there a simple way to delete a list element by value?Putting a simple if-then-else statement on one lineThreading pool similar to the multiprocessing Pool?Multiprocessing vs Threading PythonCalling functions with argparseSolution to multiprocessing error in Ipython Notebook?How can I fix this AttributeError?
Will tsunami waves travel forever if there was no land?
What is the relationship between spectral sequences and obstruction theory?
How do I deal with a coworker that keeps asking to make small superficial changes to a report, and it is seriously triggering my anxiety?
Fizzy, soft, pop and still drinks
What is the strongest case that can be made in favour of the UK regaining some control over fishing policy after Brexit?
What happened to Captain America in Endgame?
What are the potential pitfalls when using metals as a currency?
In order to check if a field is required or not, is the result of isNillable method sufficient?
Apply MapThread to all but one variable
How to pronounce 'C++' in Spanish
Are Boeing 737-800’s grounded?
Map of water taps to fill bottles
What language was spoken in East Asia before Proto-Turkic?
How do I reattach a shelf to the wall when it ripped out of the wall?
A Note on N!
Is it possible to determine the symmetric encryption method used by output size?
How exactly does Hawking radiation decrease the mass of black holes?
Minor Revision with suggestion of an alternative proof by reviewer
Combinable filters
How to verbalise code in Mathematica?
What route did the Hindenburg take when traveling from Germany to the U.S.?
How would one muzzle a full grown polar bear in the 13th century?
Is there really no use for MD5 anymore?
Is there an official tutorial for installing Ubuntu 18.04+ on a device with an SSD and an additional internal hard drive?
Simple multiprocessing code, doesn't call callback
Calling a function of a module by using its name (a string)How should I unit test threaded code?Calling an external command in PythonIs there a simple way to delete a list element by value?Putting a simple if-then-else statement on one lineThreading pool similar to the multiprocessing Pool?Multiprocessing vs Threading PythonCalling functions with argparseSolution to multiprocessing error in Ipython Notebook?How can I fix this AttributeError?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
I have that simple code, and it doesn't call the pipeline function at all
I don't know where is the problem, the function is not called, is it a problem of importing those stuff ? There is a tensorflow import that is a class that uses it
import numpy as np
import time
import Sort_Algorithm
import cv2
import os
import argparse
import helpers
import detector
import json
from collections import defaultdict
from shapely.geometry import Point, LineString
import pandas as pd
from io import StringIO
from matplotlib.path import Path
import time
import datetime
from interaction import (Behavior, Interaction, select_slice,
CODE_DEFAULT, CODE_MSG, CODE_RES)
import asyncio
from geom import Region, compute_max_polygon_diagonal
from parameter import RawParameterProcessor
from multiprocessing.pool import ThreadPool
from collections import deque
from multiprocessing import Pool, Queue
def pipeline():
while True:
print("hello")
def main():
pool = Pool(processes=2)
for i in range(0,10):
pool.apply_async(pipeline, args = (i))
pool.close()
pool.join()
if __name__ == "__main__":
main()
python multithreading
add a comment |
I have that simple code, and it doesn't call the pipeline function at all
I don't know where is the problem, the function is not called, is it a problem of importing those stuff ? There is a tensorflow import that is a class that uses it
import numpy as np
import time
import Sort_Algorithm
import cv2
import os
import argparse
import helpers
import detector
import json
from collections import defaultdict
from shapely.geometry import Point, LineString
import pandas as pd
from io import StringIO
from matplotlib.path import Path
import time
import datetime
from interaction import (Behavior, Interaction, select_slice,
CODE_DEFAULT, CODE_MSG, CODE_RES)
import asyncio
from geom import Region, compute_max_polygon_diagonal
from parameter import RawParameterProcessor
from multiprocessing.pool import ThreadPool
from collections import deque
from multiprocessing import Pool, Queue
def pipeline():
while True:
print("hello")
def main():
pool = Pool(processes=2)
for i in range(0,10):
pool.apply_async(pipeline, args = (i))
pool.close()
pool.join()
if __name__ == "__main__":
main()
python multithreading
1
Seems most of those imports are not relevant to the question - please read Minimal, Complete, and Verifiable example. Where/what is the callback? What makes you think it is not executing?
– wwii
Mar 22 at 17:33
you can remove all the imports and it won't work... it doesn't print hello
– Waleed Saleh
Mar 22 at 17:42
1
Why do youimport Queueand then not put anything into it? What example were you trying to follow that led you to code this?
– Reedinationer
Mar 22 at 17:43
You're not usingasyncioeither.
– martineau
Mar 22 at 18:17
add a comment |
I have that simple code, and it doesn't call the pipeline function at all
I don't know where is the problem, the function is not called, is it a problem of importing those stuff ? There is a tensorflow import that is a class that uses it
import numpy as np
import time
import Sort_Algorithm
import cv2
import os
import argparse
import helpers
import detector
import json
from collections import defaultdict
from shapely.geometry import Point, LineString
import pandas as pd
from io import StringIO
from matplotlib.path import Path
import time
import datetime
from interaction import (Behavior, Interaction, select_slice,
CODE_DEFAULT, CODE_MSG, CODE_RES)
import asyncio
from geom import Region, compute_max_polygon_diagonal
from parameter import RawParameterProcessor
from multiprocessing.pool import ThreadPool
from collections import deque
from multiprocessing import Pool, Queue
def pipeline():
while True:
print("hello")
def main():
pool = Pool(processes=2)
for i in range(0,10):
pool.apply_async(pipeline, args = (i))
pool.close()
pool.join()
if __name__ == "__main__":
main()
python multithreading
I have that simple code, and it doesn't call the pipeline function at all
I don't know where is the problem, the function is not called, is it a problem of importing those stuff ? There is a tensorflow import that is a class that uses it
import numpy as np
import time
import Sort_Algorithm
import cv2
import os
import argparse
import helpers
import detector
import json
from collections import defaultdict
from shapely.geometry import Point, LineString
import pandas as pd
from io import StringIO
from matplotlib.path import Path
import time
import datetime
from interaction import (Behavior, Interaction, select_slice,
CODE_DEFAULT, CODE_MSG, CODE_RES)
import asyncio
from geom import Region, compute_max_polygon_diagonal
from parameter import RawParameterProcessor
from multiprocessing.pool import ThreadPool
from collections import deque
from multiprocessing import Pool, Queue
def pipeline():
while True:
print("hello")
def main():
pool = Pool(processes=2)
for i in range(0,10):
pool.apply_async(pipeline, args = (i))
pool.close()
pool.join()
if __name__ == "__main__":
main()
python multithreading
python multithreading
asked Mar 22 at 17:24
Waleed SalehWaleed Saleh
225
225
1
Seems most of those imports are not relevant to the question - please read Minimal, Complete, and Verifiable example. Where/what is the callback? What makes you think it is not executing?
– wwii
Mar 22 at 17:33
you can remove all the imports and it won't work... it doesn't print hello
– Waleed Saleh
Mar 22 at 17:42
1
Why do youimport Queueand then not put anything into it? What example were you trying to follow that led you to code this?
– Reedinationer
Mar 22 at 17:43
You're not usingasyncioeither.
– martineau
Mar 22 at 18:17
add a comment |
1
Seems most of those imports are not relevant to the question - please read Minimal, Complete, and Verifiable example. Where/what is the callback? What makes you think it is not executing?
– wwii
Mar 22 at 17:33
you can remove all the imports and it won't work... it doesn't print hello
– Waleed Saleh
Mar 22 at 17:42
1
Why do youimport Queueand then not put anything into it? What example were you trying to follow that led you to code this?
– Reedinationer
Mar 22 at 17:43
You're not usingasyncioeither.
– martineau
Mar 22 at 18:17
1
1
Seems most of those imports are not relevant to the question - please read Minimal, Complete, and Verifiable example. Where/what is the callback? What makes you think it is not executing?
– wwii
Mar 22 at 17:33
Seems most of those imports are not relevant to the question - please read Minimal, Complete, and Verifiable example. Where/what is the callback? What makes you think it is not executing?
– wwii
Mar 22 at 17:33
you can remove all the imports and it won't work... it doesn't print hello
– Waleed Saleh
Mar 22 at 17:42
you can remove all the imports and it won't work... it doesn't print hello
– Waleed Saleh
Mar 22 at 17:42
1
1
Why do you
import Queue and then not put anything into it? What example were you trying to follow that led you to code this?– Reedinationer
Mar 22 at 17:43
Why do you
import Queue and then not put anything into it? What example were you trying to follow that led you to code this?– Reedinationer
Mar 22 at 17:43
You're not using
asyncio either.– martineau
Mar 22 at 18:17
You're not using
asyncio either.– martineau
Mar 22 at 18:17
add a comment |
1 Answer
1
active
oldest
votes
I hope you are doing good.
It seems the issue is that it silently failed.
I have used this simplify code of yours:
from multiprocessing import Pool, Queue
def pipeline(i):
while True:
print("hello")
def main():
pool = Pool(processes=2)
for i in range(0, 10):
pool.apply_async(pipeline, args=(i,))
pool.close()
pool.join()
if __name__ == "__main__":
main()
I have changed two things, args parameter in apply_async is now a tuple, the function pipeline takes correctly the given parameter by defining it in its function declaration.
pool.apply_async(pipeline, args=(i))
# to
pool.apply_async(pipeline, args=(i,))
and:
def pipeline():
while True:
print("hello")
# to
def pipeline(i):
while True:
print("hello")
If you don't need at all the parameter in pipeline, you can also write the following code (we don't pass any parameter):
from multiprocessing import Pool, Queue
def pipeline():
while True:
print("hello")
def main():
pool = Pool(processes=2)
for i in range(0, 10):
pool.apply_async(pipeline)
pool.close()
pool.join()
if __name__ == "__main__":
main()
Have a lovely day.
G
OP mentioned a callback but was not using one. This extends the toy example to use a callback and gather the results from the apply_async calls.
def pipeline(i):
return i*2
def cb(n):
print(f'foo: n')
def main():
pool = Pool(processes=2)
results= []
for i in range(0,8):
results.append(pool.apply_async(pipeline, args=(i,), callback=cb))
pool.close()
pool.join()
return results
if __name__ == "__main__":
results = main()
print([result.get() for result in results])
Which prints:
foo: 0
foo: 2
foo: 4
foo: 6
foo: 8
foo: 10
foo: 12
foo: 14
[0, 2, 4, 6, 8, 10, 12, 14]
>>>
1
Definitely theargsargument was wrong.
– wwii
Mar 22 at 17:47
Indeed, we can also completely remove it, I am going to update the answer !
– Guillaume Lastecoueres
Mar 22 at 17:51
Mind if I add something?
– wwii
Mar 22 at 17:55
Not at all, feel free :) !
– Guillaume Lastecoueres
Mar 22 at 17:57
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%2f55304863%2fsimple-multiprocessing-code-doesnt-call-callback%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
I hope you are doing good.
It seems the issue is that it silently failed.
I have used this simplify code of yours:
from multiprocessing import Pool, Queue
def pipeline(i):
while True:
print("hello")
def main():
pool = Pool(processes=2)
for i in range(0, 10):
pool.apply_async(pipeline, args=(i,))
pool.close()
pool.join()
if __name__ == "__main__":
main()
I have changed two things, args parameter in apply_async is now a tuple, the function pipeline takes correctly the given parameter by defining it in its function declaration.
pool.apply_async(pipeline, args=(i))
# to
pool.apply_async(pipeline, args=(i,))
and:
def pipeline():
while True:
print("hello")
# to
def pipeline(i):
while True:
print("hello")
If you don't need at all the parameter in pipeline, you can also write the following code (we don't pass any parameter):
from multiprocessing import Pool, Queue
def pipeline():
while True:
print("hello")
def main():
pool = Pool(processes=2)
for i in range(0, 10):
pool.apply_async(pipeline)
pool.close()
pool.join()
if __name__ == "__main__":
main()
Have a lovely day.
G
OP mentioned a callback but was not using one. This extends the toy example to use a callback and gather the results from the apply_async calls.
def pipeline(i):
return i*2
def cb(n):
print(f'foo: n')
def main():
pool = Pool(processes=2)
results= []
for i in range(0,8):
results.append(pool.apply_async(pipeline, args=(i,), callback=cb))
pool.close()
pool.join()
return results
if __name__ == "__main__":
results = main()
print([result.get() for result in results])
Which prints:
foo: 0
foo: 2
foo: 4
foo: 6
foo: 8
foo: 10
foo: 12
foo: 14
[0, 2, 4, 6, 8, 10, 12, 14]
>>>
1
Definitely theargsargument was wrong.
– wwii
Mar 22 at 17:47
Indeed, we can also completely remove it, I am going to update the answer !
– Guillaume Lastecoueres
Mar 22 at 17:51
Mind if I add something?
– wwii
Mar 22 at 17:55
Not at all, feel free :) !
– Guillaume Lastecoueres
Mar 22 at 17:57
add a comment |
I hope you are doing good.
It seems the issue is that it silently failed.
I have used this simplify code of yours:
from multiprocessing import Pool, Queue
def pipeline(i):
while True:
print("hello")
def main():
pool = Pool(processes=2)
for i in range(0, 10):
pool.apply_async(pipeline, args=(i,))
pool.close()
pool.join()
if __name__ == "__main__":
main()
I have changed two things, args parameter in apply_async is now a tuple, the function pipeline takes correctly the given parameter by defining it in its function declaration.
pool.apply_async(pipeline, args=(i))
# to
pool.apply_async(pipeline, args=(i,))
and:
def pipeline():
while True:
print("hello")
# to
def pipeline(i):
while True:
print("hello")
If you don't need at all the parameter in pipeline, you can also write the following code (we don't pass any parameter):
from multiprocessing import Pool, Queue
def pipeline():
while True:
print("hello")
def main():
pool = Pool(processes=2)
for i in range(0, 10):
pool.apply_async(pipeline)
pool.close()
pool.join()
if __name__ == "__main__":
main()
Have a lovely day.
G
OP mentioned a callback but was not using one. This extends the toy example to use a callback and gather the results from the apply_async calls.
def pipeline(i):
return i*2
def cb(n):
print(f'foo: n')
def main():
pool = Pool(processes=2)
results= []
for i in range(0,8):
results.append(pool.apply_async(pipeline, args=(i,), callback=cb))
pool.close()
pool.join()
return results
if __name__ == "__main__":
results = main()
print([result.get() for result in results])
Which prints:
foo: 0
foo: 2
foo: 4
foo: 6
foo: 8
foo: 10
foo: 12
foo: 14
[0, 2, 4, 6, 8, 10, 12, 14]
>>>
1
Definitely theargsargument was wrong.
– wwii
Mar 22 at 17:47
Indeed, we can also completely remove it, I am going to update the answer !
– Guillaume Lastecoueres
Mar 22 at 17:51
Mind if I add something?
– wwii
Mar 22 at 17:55
Not at all, feel free :) !
– Guillaume Lastecoueres
Mar 22 at 17:57
add a comment |
I hope you are doing good.
It seems the issue is that it silently failed.
I have used this simplify code of yours:
from multiprocessing import Pool, Queue
def pipeline(i):
while True:
print("hello")
def main():
pool = Pool(processes=2)
for i in range(0, 10):
pool.apply_async(pipeline, args=(i,))
pool.close()
pool.join()
if __name__ == "__main__":
main()
I have changed two things, args parameter in apply_async is now a tuple, the function pipeline takes correctly the given parameter by defining it in its function declaration.
pool.apply_async(pipeline, args=(i))
# to
pool.apply_async(pipeline, args=(i,))
and:
def pipeline():
while True:
print("hello")
# to
def pipeline(i):
while True:
print("hello")
If you don't need at all the parameter in pipeline, you can also write the following code (we don't pass any parameter):
from multiprocessing import Pool, Queue
def pipeline():
while True:
print("hello")
def main():
pool = Pool(processes=2)
for i in range(0, 10):
pool.apply_async(pipeline)
pool.close()
pool.join()
if __name__ == "__main__":
main()
Have a lovely day.
G
OP mentioned a callback but was not using one. This extends the toy example to use a callback and gather the results from the apply_async calls.
def pipeline(i):
return i*2
def cb(n):
print(f'foo: n')
def main():
pool = Pool(processes=2)
results= []
for i in range(0,8):
results.append(pool.apply_async(pipeline, args=(i,), callback=cb))
pool.close()
pool.join()
return results
if __name__ == "__main__":
results = main()
print([result.get() for result in results])
Which prints:
foo: 0
foo: 2
foo: 4
foo: 6
foo: 8
foo: 10
foo: 12
foo: 14
[0, 2, 4, 6, 8, 10, 12, 14]
>>>
I hope you are doing good.
It seems the issue is that it silently failed.
I have used this simplify code of yours:
from multiprocessing import Pool, Queue
def pipeline(i):
while True:
print("hello")
def main():
pool = Pool(processes=2)
for i in range(0, 10):
pool.apply_async(pipeline, args=(i,))
pool.close()
pool.join()
if __name__ == "__main__":
main()
I have changed two things, args parameter in apply_async is now a tuple, the function pipeline takes correctly the given parameter by defining it in its function declaration.
pool.apply_async(pipeline, args=(i))
# to
pool.apply_async(pipeline, args=(i,))
and:
def pipeline():
while True:
print("hello")
# to
def pipeline(i):
while True:
print("hello")
If you don't need at all the parameter in pipeline, you can also write the following code (we don't pass any parameter):
from multiprocessing import Pool, Queue
def pipeline():
while True:
print("hello")
def main():
pool = Pool(processes=2)
for i in range(0, 10):
pool.apply_async(pipeline)
pool.close()
pool.join()
if __name__ == "__main__":
main()
Have a lovely day.
G
OP mentioned a callback but was not using one. This extends the toy example to use a callback and gather the results from the apply_async calls.
def pipeline(i):
return i*2
def cb(n):
print(f'foo: n')
def main():
pool = Pool(processes=2)
results= []
for i in range(0,8):
results.append(pool.apply_async(pipeline, args=(i,), callback=cb))
pool.close()
pool.join()
return results
if __name__ == "__main__":
results = main()
print([result.get() for result in results])
Which prints:
foo: 0
foo: 2
foo: 4
foo: 6
foo: 8
foo: 10
foo: 12
foo: 14
[0, 2, 4, 6, 8, 10, 12, 14]
>>>
edited Mar 22 at 18:42
wwii
11.3k31948
11.3k31948
answered Mar 22 at 17:44
Guillaume LastecoueresGuillaume Lastecoueres
1139
1139
1
Definitely theargsargument was wrong.
– wwii
Mar 22 at 17:47
Indeed, we can also completely remove it, I am going to update the answer !
– Guillaume Lastecoueres
Mar 22 at 17:51
Mind if I add something?
– wwii
Mar 22 at 17:55
Not at all, feel free :) !
– Guillaume Lastecoueres
Mar 22 at 17:57
add a comment |
1
Definitely theargsargument was wrong.
– wwii
Mar 22 at 17:47
Indeed, we can also completely remove it, I am going to update the answer !
– Guillaume Lastecoueres
Mar 22 at 17:51
Mind if I add something?
– wwii
Mar 22 at 17:55
Not at all, feel free :) !
– Guillaume Lastecoueres
Mar 22 at 17:57
1
1
Definitely the
args argument was wrong.– wwii
Mar 22 at 17:47
Definitely the
args argument was wrong.– wwii
Mar 22 at 17:47
Indeed, we can also completely remove it, I am going to update the answer !
– Guillaume Lastecoueres
Mar 22 at 17:51
Indeed, we can also completely remove it, I am going to update the answer !
– Guillaume Lastecoueres
Mar 22 at 17:51
Mind if I add something?
– wwii
Mar 22 at 17:55
Mind if I add something?
– wwii
Mar 22 at 17:55
Not at all, feel free :) !
– Guillaume Lastecoueres
Mar 22 at 17:57
Not at all, feel free :) !
– Guillaume Lastecoueres
Mar 22 at 17:57
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%2f55304863%2fsimple-multiprocessing-code-doesnt-call-callback%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
Seems most of those imports are not relevant to the question - please read Minimal, Complete, and Verifiable example. Where/what is the callback? What makes you think it is not executing?
– wwii
Mar 22 at 17:33
you can remove all the imports and it won't work... it doesn't print hello
– Waleed Saleh
Mar 22 at 17:42
1
Why do you
import Queueand then not put anything into it? What example were you trying to follow that led you to code this?– Reedinationer
Mar 22 at 17:43
You're not using
asyncioeither.– martineau
Mar 22 at 18:17