def value_func(running, mutex): random.seed() time.sleep(random.random() * 4) mutex.acquire() print('\n\t\t\t' + str(processing.currentProcess()) + ' has finished') running.value -= 1 mutex.release()
def value_func(running, mutex): random.seed() time.sleep(random.random()*4) mutex.acquire() print '\n\t\t\t' + str(processing.currentProcess()) + ' has finished' running.value -= 1 mutex.release()
def semaphore_func(sema, mutex, running): sema.acquire() mutex.acquire() running.value += 1 print running.value, 'tasks are running' mutex.release() random.seed() time.sleep(random.random()*2) mutex.acquire() running.value -= 1 print '%s has finished' % processing.currentProcess() mutex.release() sema.release()
def semaphore_func(sema, mutex, running): sema.acquire() mutex.acquire() running.value += 1 print(running.value, 'tasks are running') mutex.release() random.seed() time.sleep(random.random() * 2) mutex.acquire() running.value -= 1 print('%s has finished' % processing.currentProcess()) mutex.release() sema.release()
def calculate(func, args): result = func(*args) return '%s says that %s%s = %s' % \ (currentProcess()._name, func.__name__, args, result)
def note(format, *args): sys.stderr.write('[%s]\t%s\n' % (currentProcess()._name, format%args))
def event_func(event): print '\t%r is waiting' % processing.currentProcess() event.wait() print '\t%r has woken up' % processing.currentProcess()
def calculate(func, args): result = func(*args) return "%s says that %s%s = %s" % (currentProcess()._name, func.__name__, args, result)
def event_func(event): print('\t%r is waiting' % processing.currentProcess()) event.wait() print('\t%r has woken up' % processing.currentProcess())
def note(format, *args): sys.stderr.write("[%s]\t%s\n" % (currentProcess()._name, format % args))