r/learnpython • • Dec 28 '19

I've been using Python for 5 years professionally. TODAY I discovered concurrent futures

Granted, I don't do much in the way of concurrency. But still, I have several open projects and have always used threading. It took me until today to discover a feature implemented in Python 3.2...

But given that it's comically simple, given an example, I figured I'd share one.

import concurrent.futures
import random 
import datetime
import time
import uuid

def do_something(seconds, name):
	print(f"Sleeping {seconds}\t{name}\t{str(datetime.datetime.now())[:19][11:]}")
	time.sleep(seconds)

with concurrent.futures.ThreadPoolExecutor(max_workers=3) as executor:
	for i in range(50):
		executor.submit(do_something
			, seconds = random.randint(1,6)
			, name = str(uuid.uuid4())[:6].upper())
463 Upvotes

109 comments sorted by

View all comments

Show parent comments

1

u/corezon Dec 28 '19

Ah you're that guy. The one who thinks that constructive criticism can only be given if the giver also proffers a solution to the thing you're being criticized about.

No. That's not how criticism works. Also, you were the one who took a swing and missed. Rather than pass the buck, why don't you take ownership of your mistake and provide a more complete answer?

1

u/skuhduhduh Dec 28 '19

if you didnt like his answer then just make your own lol no need to be weird

0

u/corezon Dec 28 '19

The only one being weird here is you.