python multithreading application for fetching messages from rabbitmq












-1















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.










share|improve this question

























  • Post attempt (code) at solving this please

    – Happypig375
    Nov 26 '18 at 10:32
















-1















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.










share|improve this question

























  • Post attempt (code) at solving this please

    – Happypig375
    Nov 26 '18 at 10:32














-1












-1








-1


1






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.










share|improve this question
















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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



















  • 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












2 Answers
2






active

oldest

votes


















0














You can try to use Process from Multiprocessing and call Process.pid function to get accesss to each process id.






share|improve this answer
























  • I want whole python program for it

    – Akshay Shinde
    Nov 26 '18 at 11:49





















0














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).






share|improve this answer
























  • 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












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
});


}
});














draft saved

draft discarded


















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









0














You can try to use Process from Multiprocessing and call Process.pid function to get accesss to each process id.






share|improve this answer
























  • I want whole python program for it

    – Akshay Shinde
    Nov 26 '18 at 11:49


















0














You can try to use Process from Multiprocessing and call Process.pid function to get accesss to each process id.






share|improve this answer
























  • I want whole python program for it

    – Akshay Shinde
    Nov 26 '18 at 11:49
















0












0








0







You can try to use Process from Multiprocessing and call Process.pid function to get accesss to each process id.






share|improve this answer













You can try to use Process from Multiprocessing and call Process.pid function to get accesss to each process id.







share|improve this answer












share|improve this answer



share|improve this answer










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





















  • 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















0














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).






share|improve this answer
























  • 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
















0














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).






share|improve this answer
























  • 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














0












0








0







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).






share|improve this answer













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).







share|improve this answer












share|improve this answer



share|improve this answer










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



















  • 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


















draft saved

draft discarded




















































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.




draft saved


draft discarded














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





















































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







Popular posts from this blog

Wiesbaden

Marschland

Dieringhausen