A
A
Akshin Yolchuev2020-05-21 17:39:34
Python
Akshin Yolchuev, 2020-05-21 17:39:34

Thread allocation in Python?

The code:

import time
t1 = time.time()
with open(r'Числа от одного до трилиарда.txt','r')as f:
  for i in f:

    print(i)

t2 = time.time()
print(t2-t1)


Threading
how to distribute so that 5-10 threads perform this task without interfering with another thread (that is, without printing a number that has already been printed) P.S
The queue library does not help because large data

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Dr. Bacon, 2020-05-21
@bacon

1. "The queue library does not help because big data" what? where did you get this from?
2. One thread reads the file and puts it in the queue, several threads are already reading from the queue.
3. But all this will not save you, print is not threadsafe, and it must be wrapped in Lock, which loses the meaning of the Wishlist.

A
Alexander, 2020-05-21
@shabelski89

queue

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question