Python Tutorials : Threading Beginners Tutorial- Queue (part 6-1)

preview_player
Показать описание
This video is part of Python Threading Beginners Tutorial playlist.
If you are new to threads please start the playlist from the
beginning.

The playlist can be found here:

Python 3.x - Queue - (Initializing 3 types of Queues) part#1

In this video, I will introduce the 3 types of queues used in Python, how to initialize them, and
some common queue methods/attributes associated with them.

Code to this lesson can be found here:

Please leave feedback as to what you like and what you would like to see.

Thank you.

Code to this lesson can be found here:

Please leave feedback as to what you like and what you would like to see.

Thank you.
Рекомендации по теме
Комментарии
Автор

Thank you for posting this video. I've been struggling with finding a solution to return values form threads. This example was straight forward and easy to understand!

stevebaia
Автор

9:00 the reason the comma in brackets is needed is because python outputs a string/int with a single value tuple . This is how the x, y = y, x and a, b = (1, 2) functionality that we all know and love works.

To escape this behaviour you need to add a comma so a tuple len() = 1 is returned.

print(type(a = (1))) is an int obj.
print(type(a = ("foo"))) is an str obj.
print(type(a = (1, ))) is a tuple obj.
As is ("foo", )

fecu
Автор

0:57 LIFO (Last in First out) is Stack's principle.
--> Queue's principle is LILO (Last in Last out)

mr.progammer
Автор

I use q.get_nowait() to avoid freezing.
Thank you for easy explaination.

Turjak_art
Автор

What is the difference, or when should you use deque from collections vs queue.Queue vs multiprocessing.Queue?

performance

bennguyen
Автор

I think daemon threads life cycle is associated to the calling thread so, by using join() on the thread i thing bug will be resolved

sameerarote
Автор

I believe if you did t.join() at the end of your program, the daemon would terminate and you wouldn't get the bug you described.

dwestley
Автор

Well structured, but I don't understand how q still works without defining it.

carsonyt
Автор

If I have my terminology right, 'threadsafe' means that the problem of two or more threads mutating the same value at the same time is prevented, and this is why we have locks. However, my question is whether the mere presence of a queue also guarantees that the process of getting values off the queue is threadsafe? In other words, what is to stop two or more threads from taking the same value off the queue at the same time? For that matter, how do we know that flags are threadsafe? Once the flag is thrown, what is to stop two threads from accessing the same value at the same time? I don't think you have made this explicit in any of these videos except the one on locks. Otherwise, they've been great. Thank you for clarifying.

malikrumi
Автор

but in min 5:10 q = queue.Queue() is dashed ?? why you still geta a right output ?

maherazzzouzi
Автор

08:50 Single arg doesn't work because it expects a tuple. With single argument you have to use a trailing comma because it changes the argument list into a tuple. Without the trailing comma a single value in parentheses is just that value in parentheses.

josephturi
Автор

5:06 Why run this code without "q=queue.Queue()"

changyoung
Автор

5:04 Am I stupid or should this not work?!

Edit: Omfg, I got it. He runs it in an environment where variables are persisted from the previous script he ran, thus last time he had defined q and that's what is used now which is why it doesn't error out.

vesizoiper