python multithreading application for fetching messages from rabbitmq
Worker.counter =0
confobj.thread_count =2
def callback(ch, method, properties, body):
if(Worker.counter<confobj.thread_count):
logObject = json.loads(body)
th=Worker(Worker.counter+1,logObject,confobj,fileobj)
Worker.counter+=1
th.start()
else:
print("All threads are busy.")
time.sleep(2)
ch.basic_ack(delivery_tag = method.delivery_tag)
channel.basic_qos(prefetch_count=1)
channel.basic_consume(callback,
queu`enter code here`e=confobj.queue)
channel.start_consuming()
I want maxthread should be 2 such that first message is accessed by first thread, second message by second thread, third message by first thread again and so on
And then I want to insert that messages into elastic search without skipping any of messages.
python-3.x multithreading rabbitmq
add a comment |
Worker.counter =0
confobj.thread_count =2
def callback(ch, method, properties, body):
if(Worker.counter<confobj.thread_count):
logObject = json.loads(body)
th=Worker(Worker.counter+1,logObject,confobj,fileobj)
Worker.counter+=1
th.start()
else:
print("All threads are busy.")
time.sleep(2)
ch.basic_ack(delivery_tag = method.delivery_tag)
channel.basic_qos(prefetch_count=1)
channel.basic_consume(callback,
queu`enter code here`e=confobj.queue)
channel.start_consuming()
I want maxthread should be 2 such that first message is accessed by first thread, second message by second thread, third message by first thread again and so on
And then I want to insert that messages into elastic search without skipping any of messages.
python-3.x multithreading rabbitmq
Post attempt (code) at solving this please
– Happypig375
Nov 26 '18 at 10:32
add a comment |
Worker.counter =0
confobj.thread_count =2
def callback(ch, method, properties, body):
if(Worker.counter<confobj.thread_count):
logObject = json.loads(body)
th=Worker(Worker.counter+1,logObject,confobj,fileobj)
Worker.counter+=1
th.start()
else:
print("All threads are busy.")
time.sleep(2)
ch.basic_ack(delivery_tag = method.delivery_tag)
channel.basic_qos(prefetch_count=1)
channel.basic_consume(callback,
queu`enter code here`e=confobj.queue)
channel.start_consuming()
I want maxthread should be 2 such that first message is accessed by first thread, second message by second thread, third message by first thread again and so on
And then I want to insert that messages into elastic search without skipping any of messages.
python-3.x multithreading rabbitmq
Worker.counter =0
confobj.thread_count =2
def callback(ch, method, properties, body):
if(Worker.counter<confobj.thread_count):
logObject = json.loads(body)
th=Worker(Worker.counter+1,logObject,confobj,fileobj)
Worker.counter+=1
th.start()
else:
print("All threads are busy.")
time.sleep(2)
ch.basic_ack(delivery_tag = method.delivery_tag)
channel.basic_qos(prefetch_count=1)
channel.basic_consume(callback,
queu`enter code here`e=confobj.queue)
channel.start_consuming()
I want maxthread should be 2 such that first message is accessed by first thread, second message by second thread, third message by first thread again and so on
And then I want to insert that messages into elastic search without skipping any of messages.
python-3.x multithreading rabbitmq
python-3.x multithreading rabbitmq
edited Jan 4 at 11:05
Akshay Shinde
asked Nov 26 '18 at 10:15
Akshay ShindeAkshay Shinde
12
12
Post attempt (code) at solving this please
– Happypig375
Nov 26 '18 at 10:32
add a comment |
Post attempt (code) at solving this please
– Happypig375
Nov 26 '18 at 10:32
Post attempt (code) at solving this please
– Happypig375
Nov 26 '18 at 10:32
Post attempt (code) at solving this please
– Happypig375
Nov 26 '18 at 10:32
add a comment |
2 Answers
2
active
oldest
votes
You can try to use Process from Multiprocessing and call Process.pid function to get accesss to each process id.
I want whole python program for it
– Akshay Shinde
Nov 26 '18 at 11:49
add a comment |
from multiprocessing import Process, current_process
def square(x):
print(x*x)
print('processID =', current_process())
return x * x
def cube(y):
print(y*y*y)
print('processID =', current_process())
return y * y * y
if __name__ == '__main__':
number = 6
one = Process(target=square, args=(number,))
two = Process(target=cube, args=(number,))
one.start()
two.start()
one.join()
two.join()
Here is a simple example of using Process with different functions. Therefore you can call .start() by Process Id. (It's not a complite code. It's just an example for understanding).
I want to access 4 messages with two threads , what should I do ?
– Akshay Shinde
Nov 27 '18 at 10:08
What does it exactly mean? As i understood, you need sort of a cicle with 3 threads or processes, that use individual thread for every third element of the processed list.
– Alexander
Nov 27 '18 at 11:19
add a comment |
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%2f53478924%2fpython-multithreading-application-for-fetching-messages-from-rabbitmq%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 can try to use Process from Multiprocessing and call Process.pid function to get accesss to each process id.
I want whole python program for it
– Akshay Shinde
Nov 26 '18 at 11:49
add a comment |
You can try to use Process from Multiprocessing and call Process.pid function to get accesss to each process id.
I want whole python program for it
– Akshay Shinde
Nov 26 '18 at 11:49
add a comment |
You can try to use Process from Multiprocessing and call Process.pid function to get accesss to each process id.
You can try to use Process from Multiprocessing and call Process.pid function to get accesss to each process id.
answered Nov 26 '18 at 11:13
AlexanderAlexander
317
317
I want whole python program for it
– Akshay Shinde
Nov 26 '18 at 11:49
add a comment |
I want whole python program for it
– Akshay Shinde
Nov 26 '18 at 11:49
I want whole python program for it
– Akshay Shinde
Nov 26 '18 at 11:49
I want whole python program for it
– Akshay Shinde
Nov 26 '18 at 11:49
add a comment |
from multiprocessing import Process, current_process
def square(x):
print(x*x)
print('processID =', current_process())
return x * x
def cube(y):
print(y*y*y)
print('processID =', current_process())
return y * y * y
if __name__ == '__main__':
number = 6
one = Process(target=square, args=(number,))
two = Process(target=cube, args=(number,))
one.start()
two.start()
one.join()
two.join()
Here is a simple example of using Process with different functions. Therefore you can call .start() by Process Id. (It's not a complite code. It's just an example for understanding).
I want to access 4 messages with two threads , what should I do ?
– Akshay Shinde
Nov 27 '18 at 10:08
What does it exactly mean? As i understood, you need sort of a cicle with 3 threads or processes, that use individual thread for every third element of the processed list.
– Alexander
Nov 27 '18 at 11:19
add a comment |
from multiprocessing import Process, current_process
def square(x):
print(x*x)
print('processID =', current_process())
return x * x
def cube(y):
print(y*y*y)
print('processID =', current_process())
return y * y * y
if __name__ == '__main__':
number = 6
one = Process(target=square, args=(number,))
two = Process(target=cube, args=(number,))
one.start()
two.start()
one.join()
two.join()
Here is a simple example of using Process with different functions. Therefore you can call .start() by Process Id. (It's not a complite code. It's just an example for understanding).
I want to access 4 messages with two threads , what should I do ?
– Akshay Shinde
Nov 27 '18 at 10:08
What does it exactly mean? As i understood, you need sort of a cicle with 3 threads or processes, that use individual thread for every third element of the processed list.
– Alexander
Nov 27 '18 at 11:19
add a comment |
from multiprocessing import Process, current_process
def square(x):
print(x*x)
print('processID =', current_process())
return x * x
def cube(y):
print(y*y*y)
print('processID =', current_process())
return y * y * y
if __name__ == '__main__':
number = 6
one = Process(target=square, args=(number,))
two = Process(target=cube, args=(number,))
one.start()
two.start()
one.join()
two.join()
Here is a simple example of using Process with different functions. Therefore you can call .start() by Process Id. (It's not a complite code. It's just an example for understanding).
from multiprocessing import Process, current_process
def square(x):
print(x*x)
print('processID =', current_process())
return x * x
def cube(y):
print(y*y*y)
print('processID =', current_process())
return y * y * y
if __name__ == '__main__':
number = 6
one = Process(target=square, args=(number,))
two = Process(target=cube, args=(number,))
one.start()
two.start()
one.join()
two.join()
Here is a simple example of using Process with different functions. Therefore you can call .start() by Process Id. (It's not a complite code. It's just an example for understanding).
answered Nov 26 '18 at 12:27
AlexanderAlexander
317
317
I want to access 4 messages with two threads , what should I do ?
– Akshay Shinde
Nov 27 '18 at 10:08
What does it exactly mean? As i understood, you need sort of a cicle with 3 threads or processes, that use individual thread for every third element of the processed list.
– Alexander
Nov 27 '18 at 11:19
add a comment |
I want to access 4 messages with two threads , what should I do ?
– Akshay Shinde
Nov 27 '18 at 10:08
What does it exactly mean? As i understood, you need sort of a cicle with 3 threads or processes, that use individual thread for every third element of the processed list.
– Alexander
Nov 27 '18 at 11:19
I want to access 4 messages with two threads , what should I do ?
– Akshay Shinde
Nov 27 '18 at 10:08
I want to access 4 messages with two threads , what should I do ?
– Akshay Shinde
Nov 27 '18 at 10:08
What does it exactly mean? As i understood, you need sort of a cicle with 3 threads or processes, that use individual thread for every third element of the processed list.
– Alexander
Nov 27 '18 at 11:19
What does it exactly mean? As i understood, you need sort of a cicle with 3 threads or processes, that use individual thread for every third element of the processed list.
– Alexander
Nov 27 '18 at 11:19
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%2f53478924%2fpython-multithreading-application-for-fetching-messages-from-rabbitmq%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
Post attempt (code) at solving this please
– Happypig375
Nov 26 '18 at 10:32