multiprocessing help: launching Loops2019 Community Moderator ElectionAccessing the index in 'for' loops?python multiprocessing vs threading for cpu bound work on windows and linuxMultiprocessing vs Threading PythonIterating over dictionaries using 'for' loopsPython multiprocessing pool.map for multiple argumentsWhat kind of problems (if any) would there be combining asyncio with multiprocessing?Python Sync Variables in multiprocessingHow to read all message from queue using stomp library in Python?How to execute code just before terminating the process in python?Python in Linux child process not detecting changes in dictionary in parent process
Why aren't there more Gauls like Obelix?
Exempt portion of equation line from aligning?
PTIJ: Sport in the Torah
Why do we say 'Pairwise Disjoint', rather than 'Disjoint'?
How do you use environments that have the same name within a single latex document?
An Undercover Army
Why does this boat have a landing pad? (SpaceX's GO Searcher) Any plans for propulsive capsule landings?
Giving a career talk in my old university, how prominently should I tell students my salary?
After Brexit, will the EU recognize British passports that are valid for more than ten years?
Was it really inappropriate to write a pull request for the company I interviewed with?
Are small insurances worth it?
How can I have x-axis ticks that show ticks scaled in powers of ten?
Help! My Character is too much for her story!
Why do phishing e-mails use faked e-mail addresses instead of the real one?
Was this cameo in Captain Marvel computer generated?
Can the Witch Sight warlock invocation see through the Mirror Image spell?
Interpretation of linear regression interaction term plot
Generating a list with duplicate entries
Why does a car's steering wheel get lighter with increasing speed
Is there a logarithm base for which the logarithm becomes an identity function?
Inorganic chemistry handbook with reaction lists
Why do we call complex numbers “numbers” but we don’t consider 2-vectors numbers?
What is the oldest European royal house?
The (Easy) Road to Code
multiprocessing help: launching Loops
2019 Community Moderator ElectionAccessing the index in 'for' loops?python multiprocessing vs threading for cpu bound work on windows and linuxMultiprocessing vs Threading PythonIterating over dictionaries using 'for' loopsPython multiprocessing pool.map for multiple argumentsWhat kind of problems (if any) would there be combining asyncio with multiprocessing?Python Sync Variables in multiprocessingHow to read all message from queue using stomp library in Python?How to execute code just before terminating the process in python?Python in Linux child process not detecting changes in dictionary in parent process
What I have:
Web application that does some things, running on Bottle microframework, here is the Main
def run_server():
bottle.run(host=env.str('SRVRIP'), port=env.str('SRVRPORT'), debug=False)
# Main
if __name__ == '__main__':
run_server()
What I want to add:
I want to split this app in 2 processes: first called main_service()
which simply runs the server, second called backup_service()
which has to take a periodic Db backup (once per hour)
What I've tried
First I've tried with the asyncio
module, failing miserably (tried just for fun and to understand something new).
Now I'm facing on multiprocessing
(leaving aside threading cause I don't want GIL troubles), but I can't understand how to make it work, here is my code:
import multiprocessing
import time
import os
def main_service():
print(f'Process os.getpid()')
while(True):
sentence=input()
print(f'USER: sentence')
def backup_service():
print(f'Process os.getpgid()')
while(True):
print('BACKUP')
time.sleep(1)
if __name__ == "__main__":
processes = []
t = multiprocessing.Process(target=main_service())
processes.append(t)
t.start()
t = multiprocessing.Process(target=backup_service())
processes.append(t)
t.start()
for process in processes:
process.join()
print('Done')
If run
Process 14608
As you can see
USER: As you can see
It asks for input
USER: It asks for input
But backup_service() is not printing anything
USER: But backup_service() is not printing anything
Expected output
Process 14608
While I'm writing
USER: While I'm writing
BACKUP
every second
USER: every second
backup_service() has to print 'BACKUP'
USER: backup_service() has to print 'BACKUP'
BACKUP
Can anyone help?
python multiprocessing
add a comment |
What I have:
Web application that does some things, running on Bottle microframework, here is the Main
def run_server():
bottle.run(host=env.str('SRVRIP'), port=env.str('SRVRPORT'), debug=False)
# Main
if __name__ == '__main__':
run_server()
What I want to add:
I want to split this app in 2 processes: first called main_service()
which simply runs the server, second called backup_service()
which has to take a periodic Db backup (once per hour)
What I've tried
First I've tried with the asyncio
module, failing miserably (tried just for fun and to understand something new).
Now I'm facing on multiprocessing
(leaving aside threading cause I don't want GIL troubles), but I can't understand how to make it work, here is my code:
import multiprocessing
import time
import os
def main_service():
print(f'Process os.getpid()')
while(True):
sentence=input()
print(f'USER: sentence')
def backup_service():
print(f'Process os.getpgid()')
while(True):
print('BACKUP')
time.sleep(1)
if __name__ == "__main__":
processes = []
t = multiprocessing.Process(target=main_service())
processes.append(t)
t.start()
t = multiprocessing.Process(target=backup_service())
processes.append(t)
t.start()
for process in processes:
process.join()
print('Done')
If run
Process 14608
As you can see
USER: As you can see
It asks for input
USER: It asks for input
But backup_service() is not printing anything
USER: But backup_service() is not printing anything
Expected output
Process 14608
While I'm writing
USER: While I'm writing
BACKUP
every second
USER: every second
backup_service() has to print 'BACKUP'
USER: backup_service() has to print 'BACKUP'
BACKUP
Can anyone help?
python multiprocessing
add a comment |
What I have:
Web application that does some things, running on Bottle microframework, here is the Main
def run_server():
bottle.run(host=env.str('SRVRIP'), port=env.str('SRVRPORT'), debug=False)
# Main
if __name__ == '__main__':
run_server()
What I want to add:
I want to split this app in 2 processes: first called main_service()
which simply runs the server, second called backup_service()
which has to take a periodic Db backup (once per hour)
What I've tried
First I've tried with the asyncio
module, failing miserably (tried just for fun and to understand something new).
Now I'm facing on multiprocessing
(leaving aside threading cause I don't want GIL troubles), but I can't understand how to make it work, here is my code:
import multiprocessing
import time
import os
def main_service():
print(f'Process os.getpid()')
while(True):
sentence=input()
print(f'USER: sentence')
def backup_service():
print(f'Process os.getpgid()')
while(True):
print('BACKUP')
time.sleep(1)
if __name__ == "__main__":
processes = []
t = multiprocessing.Process(target=main_service())
processes.append(t)
t.start()
t = multiprocessing.Process(target=backup_service())
processes.append(t)
t.start()
for process in processes:
process.join()
print('Done')
If run
Process 14608
As you can see
USER: As you can see
It asks for input
USER: It asks for input
But backup_service() is not printing anything
USER: But backup_service() is not printing anything
Expected output
Process 14608
While I'm writing
USER: While I'm writing
BACKUP
every second
USER: every second
backup_service() has to print 'BACKUP'
USER: backup_service() has to print 'BACKUP'
BACKUP
Can anyone help?
python multiprocessing
What I have:
Web application that does some things, running on Bottle microframework, here is the Main
def run_server():
bottle.run(host=env.str('SRVRIP'), port=env.str('SRVRPORT'), debug=False)
# Main
if __name__ == '__main__':
run_server()
What I want to add:
I want to split this app in 2 processes: first called main_service()
which simply runs the server, second called backup_service()
which has to take a periodic Db backup (once per hour)
What I've tried
First I've tried with the asyncio
module, failing miserably (tried just for fun and to understand something new).
Now I'm facing on multiprocessing
(leaving aside threading cause I don't want GIL troubles), but I can't understand how to make it work, here is my code:
import multiprocessing
import time
import os
def main_service():
print(f'Process os.getpid()')
while(True):
sentence=input()
print(f'USER: sentence')
def backup_service():
print(f'Process os.getpgid()')
while(True):
print('BACKUP')
time.sleep(1)
if __name__ == "__main__":
processes = []
t = multiprocessing.Process(target=main_service())
processes.append(t)
t.start()
t = multiprocessing.Process(target=backup_service())
processes.append(t)
t.start()
for process in processes:
process.join()
print('Done')
If run
Process 14608
As you can see
USER: As you can see
It asks for input
USER: It asks for input
But backup_service() is not printing anything
USER: But backup_service() is not printing anything
Expected output
Process 14608
While I'm writing
USER: While I'm writing
BACKUP
every second
USER: every second
backup_service() has to print 'BACKUP'
USER: backup_service() has to print 'BACKUP'
BACKUP
Can anyone help?
python multiprocessing
python multiprocessing
edited 2 days ago
martineau
68.8k1091185
68.8k1091185
asked 2 days ago
HeleHele
386
386
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
You split your app in 2 processes but then you don't know what to do in the main process: why don't you simply run only one new process (for the backup) and you keep the web server loop running in the main process that started your program?
Something like this should work (not tested):
import multiprocessing
import time
import os
def backup_service():
print(f'Process os.getpgid()')
while(True):
print('BACKUP')
time.sleep(1)
if __name__ == "__main__":
t = multiprocessing.Process(target=backup_service)
t.daemon = True
t.start()
bottle.run(host=env.str('SRVRIP'), port=env.str('SRVRPORT'), debug=False)
keep it simple...
Thanks, anyway doing this way my "main_service()" never print idk Why
– Hele
yesterday
sorry, there was a error in my code: you should pass only the function name without () to target Process.
– Gabri Ele
yesterday
add a comment |
process.join()
is never getting to the second process because process.join()
only ends when the process that it's joining terminates. In your case, the process is an infinite loop so it never terminates and it never advances the loop to the next process.
You could get around this and see some output from the other process by using the timeout option for join()
. Alternatively, you could have your processes output to different files and tail those files to confirm that they're both running.
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%2f55028034%2fmultiprocessing-help-launching-loops%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
You split your app in 2 processes but then you don't know what to do in the main process: why don't you simply run only one new process (for the backup) and you keep the web server loop running in the main process that started your program?
Something like this should work (not tested):
import multiprocessing
import time
import os
def backup_service():
print(f'Process os.getpgid()')
while(True):
print('BACKUP')
time.sleep(1)
if __name__ == "__main__":
t = multiprocessing.Process(target=backup_service)
t.daemon = True
t.start()
bottle.run(host=env.str('SRVRIP'), port=env.str('SRVRPORT'), debug=False)
keep it simple...
Thanks, anyway doing this way my "main_service()" never print idk Why
– Hele
yesterday
sorry, there was a error in my code: you should pass only the function name without () to target Process.
– Gabri Ele
yesterday
add a comment |
You split your app in 2 processes but then you don't know what to do in the main process: why don't you simply run only one new process (for the backup) and you keep the web server loop running in the main process that started your program?
Something like this should work (not tested):
import multiprocessing
import time
import os
def backup_service():
print(f'Process os.getpgid()')
while(True):
print('BACKUP')
time.sleep(1)
if __name__ == "__main__":
t = multiprocessing.Process(target=backup_service)
t.daemon = True
t.start()
bottle.run(host=env.str('SRVRIP'), port=env.str('SRVRPORT'), debug=False)
keep it simple...
Thanks, anyway doing this way my "main_service()" never print idk Why
– Hele
yesterday
sorry, there was a error in my code: you should pass only the function name without () to target Process.
– Gabri Ele
yesterday
add a comment |
You split your app in 2 processes but then you don't know what to do in the main process: why don't you simply run only one new process (for the backup) and you keep the web server loop running in the main process that started your program?
Something like this should work (not tested):
import multiprocessing
import time
import os
def backup_service():
print(f'Process os.getpgid()')
while(True):
print('BACKUP')
time.sleep(1)
if __name__ == "__main__":
t = multiprocessing.Process(target=backup_service)
t.daemon = True
t.start()
bottle.run(host=env.str('SRVRIP'), port=env.str('SRVRPORT'), debug=False)
keep it simple...
You split your app in 2 processes but then you don't know what to do in the main process: why don't you simply run only one new process (for the backup) and you keep the web server loop running in the main process that started your program?
Something like this should work (not tested):
import multiprocessing
import time
import os
def backup_service():
print(f'Process os.getpgid()')
while(True):
print('BACKUP')
time.sleep(1)
if __name__ == "__main__":
t = multiprocessing.Process(target=backup_service)
t.daemon = True
t.start()
bottle.run(host=env.str('SRVRIP'), port=env.str('SRVRPORT'), debug=False)
keep it simple...
edited yesterday
answered 2 days ago
Gabri EleGabri Ele
30328
30328
Thanks, anyway doing this way my "main_service()" never print idk Why
– Hele
yesterday
sorry, there was a error in my code: you should pass only the function name without () to target Process.
– Gabri Ele
yesterday
add a comment |
Thanks, anyway doing this way my "main_service()" never print idk Why
– Hele
yesterday
sorry, there was a error in my code: you should pass only the function name without () to target Process.
– Gabri Ele
yesterday
Thanks, anyway doing this way my "main_service()" never print idk Why
– Hele
yesterday
Thanks, anyway doing this way my "main_service()" never print idk Why
– Hele
yesterday
sorry, there was a error in my code: you should pass only the function name without () to target Process.
– Gabri Ele
yesterday
sorry, there was a error in my code: you should pass only the function name without () to target Process.
– Gabri Ele
yesterday
add a comment |
process.join()
is never getting to the second process because process.join()
only ends when the process that it's joining terminates. In your case, the process is an infinite loop so it never terminates and it never advances the loop to the next process.
You could get around this and see some output from the other process by using the timeout option for join()
. Alternatively, you could have your processes output to different files and tail those files to confirm that they're both running.
add a comment |
process.join()
is never getting to the second process because process.join()
only ends when the process that it's joining terminates. In your case, the process is an infinite loop so it never terminates and it never advances the loop to the next process.
You could get around this and see some output from the other process by using the timeout option for join()
. Alternatively, you could have your processes output to different files and tail those files to confirm that they're both running.
add a comment |
process.join()
is never getting to the second process because process.join()
only ends when the process that it's joining terminates. In your case, the process is an infinite loop so it never terminates and it never advances the loop to the next process.
You could get around this and see some output from the other process by using the timeout option for join()
. Alternatively, you could have your processes output to different files and tail those files to confirm that they're both running.
process.join()
is never getting to the second process because process.join()
only ends when the process that it's joining terminates. In your case, the process is an infinite loop so it never terminates and it never advances the loop to the next process.
You could get around this and see some output from the other process by using the timeout option for join()
. Alternatively, you could have your processes output to different files and tail those files to confirm that they're both running.
answered 2 days ago
JohnJohn
56519
56519
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%2f55028034%2fmultiprocessing-help-launching-loops%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