Learning Concurrency in Python

Книга: Learning Concurrency in Python
Назад: Example
Дальше: Output

Breaking it down

If we have a look at the preceding code, we have defined a custom class, myThread, which inherits from threading.Thread. Within this class, we define the standard __init__ function and the run function. Our __init__ function takes in our barrier object so that we can reference it later on.

Within our run function, we simulate our thread doing some work for a random amount of time between 1 and 10 seconds, and then we start waiting on the barrier.

Out with our class definition, we first create our barrier object by calling barrier = threading.Barrier(4). The 4 that we've passed into this as an argument represents the number of threads that have to be waiting on the barrier before it will be lifted. We then go on to define four distinct threads, and join them all.

Назад: Example
Дальше: Output
Показать оглавление

Комментариев: 4

Оставить комментарий

  1. MaxPowermuh
    Download missing dll from Download unarc.dll page. Fix your error now!
  2. Kimeror
    Interested in hardrock? How about KISS? They are on a tour this year all across Canada and USA. Visit KISS Tour Dates Omaha to know more about KISS concert dates in 2019.
  3. Carrieor
    Carrie Underwood is my favourite country singer. She is young, beautiful and charming female in her 30s. Her strong voice takes me away from all troubles of this world so I start enjoy my life and listen songs created by her mind. Now the singer is on a Cry Pretty 360 Tour started in May of 2019. The concerts scheduled for this year, up to the 31st of October. Tickets are available for all men and women with different income. If you love country music as mush as I, then you must visit at least one of her concert. All tour dates are available at the Carrie Underwood tour Pittsburgh. Visit the website and make yourself familiar with all powerful Carrie Underwood concerts in 2019!
  4. fff
    fffffff