Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Python Threads (You're excited already,)

Name: Anonymous 2012-02-16 0:52


####################################################
# uses simple shared global data (not mutexes) to
# know when threads are done in parent/main thread;
####################################################

import thread
stdoutmutex = thread.allocate_lock( )
exitmutexes = [0] * 10

def counter(myId, count):
    for i in range(count):
        stdoutmutex.acquire( )
        print '[%s] => %s' % (myId, i)
        stdoutmutex.release( )
    exitmutexes[myId] = 1  # signal main thread

for i in range(10):
    thread.start_new(counter, (i, 100))

while 0 in exitmutexes: pass
print 'Main thread exiting.'




[0] => 0
[1] => 0
[2] => 0
[3] => 0
[4] => 0
[5] => 0
[6] => 0
[7] => 0
[8] => 0
[9] => 0
[0] => 1
[1] => 1
[2] => 1
[3] => 1
[4] => 1
[5] => 1
[6] => 1
[7] => 1
[8] => 1
[9] => 1
[0] => 2
[1] => 2
[2] => 2
[3] => 2
[4] => 2
[5] => 2
[6] => 2
[7] => 2
[8] => 2
[9] => 2
[0] => 3
~~~ ... BunchAShitYouCareEvenLessAbout ... ~~~
[6] => 98
[7] => 98
[8] => 98
[9] => 98
[0] => 99
[1] => 99
[2] => 99
[3] => 99
[4] => 99
[5] => 99
[6] => 99
[7] => 99
[8] => 99
[9] => 99
Main thread exiting.


So I don't get this. Why does it count the numbers in order? Wouldn't a counter thread acquire itself as soon as it released itself? I don't understand why any of this is in order. I get why the processes can be out of order, but not why it counts in order.

Name: Anonymous 2012-02-19 9:59

>>3

>>2 here... I gave time to let the trolls have at it. Anyway, here's the breakdown.

You opened threads.... that process... in order. Now I know that was complicated, so here's a further break down.

Your code opens up 10 threads with 100 jobs each. Those threads process in order. Which works like this:

Thread #1: Job #1
Thread #2: Job #1
Thread #3: Job #1

And so on and so forth until all the jobs are done. See, the cool part about languages that try forcing OOP... like python. Is that your going to spend all your programming time using somebody else's shit library. Like what your doing now. Ergo, if said library doesn't do what you want... too fucking bad. And even if you do write your own library it won't be considered "pythonic". No no no, no matter what. Don't question how much these neckbeards love tearing up somebody else's shit. Yes, I'm stating clearly that it doesn't matter if a library works or not... just so long as the library is written out in a way that people will accept socially. Also.. yes, I'm very much aware that I didn't post functioning code that did what you wanted... twice now.

inb4 shitstorm over talking about forced OOP

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List