Daily Steem-Python Challenge #19, Win 1 Steem!

in #programming6 years ago (edited)

For each tutorial we release there will be a relevant challenge where the winner receives 1 STEEM!

Challenge

Take the code from the tutorial from here and change it to be able to do the following

  1. Counting blocks is perfect for multi threading as each blocks does not effect another block. Alter the code in such a way that is takes amount_of_threads as a second command line argument and equally divides the blocks to be analysed among these threads. Combine the collected data and the end.

That's it! Good luck to everyone participating!

Deadline

The prize money will be rewarded to the person that solves the problem first. If there is no solution within 7 days after this post has been submitted the prize pool expires.

Relevant Tutorial(s)


If you have questions about the tutorial or the challenge then don't hesitate to comment below or contact us on Discord!

Sort:  

Here's my solution. Hope you like it!

Nice work! I will send you the prize money.

Question:

You create a separate dict for each thread:
results.append({})

And you also lock this dict for every write:

      lock.acquire()
            if operation not in self.stats:
                self.stats[operation] = 1
            else:
                self.stats[operation] += 1
            lock.release()

Is this required since the dict is still part of the results list? I do not know, so this is a genuine question.

My solution is a bit different in that regard and also yields faster times, I will be submitting a tutorial soon.

Yeah, I don't think that lock is necessary. I used it because I thought since they are all part of a larger array I should use it to be safe, but I think it would be just as safe without. Nice catch!

Coin Marketplace

STEEM 0.29
TRX 0.12
JST 0.033
BTC 62559.43
ETH 3092.10
USDT 1.00
SBD 3.86