Archive for November, 2007

Chavez - Sindrome de doble personalidad

Friday, November 30th, 2007

Sera que finalmente se arma la de San Quintin? Le tiraran un madrugonazo? Sera que finalmente se arrechan los Venezolanos y sacan al loco (loco pila que tiene mas billete que bill gates) ?

FrostWire is featured download of Cyber Monday on Download.com

Monday, November 26th, 2007

Simply thanks, we have no words to describe how cool this is.

PyQt4: Using QMutex vs QMutexLocker.

Sunday, November 25th, 2007

Here’s some code for my future reference on how to use QMutex or QMutexLocker.

Lessons Learned:
* Use QMutex to protect data, not code. Try not to lock hughe amounts of code within a function with mutex.lock(), mutex.unlock(), if for any reason you forget to release the lock you’ll be in trouble. Use the mutex directly only when you know what it is that you want to protect concurrent access from.
* When you have a complex function and you don’t want to worry about what to protect and when to release the lock (on exceptions thrown, before returns,etc), you can create an instance of QMutexLocker and it should release the mutex lock upon destruction… this takes us to the next lesson
* When using a QMutexLocker, DO NOT make the QMutexLocker an attribute of your class, otherwise, the reference will live after the method finishes and the lock won’t be released.

Here’s some code.

from PyQt4.Qt import QObject, QMutex, QApplication, QThread, QMutexLocker
import sys

class MutexTestSubject(QObject):
	'''
	Class that uses a QMutex to synchronize
        access to its add(),substract() methods.

        This works perfectly fine.
	'''
	def __init__(self):
		QObject.__init__(self)
		self.MAX_LIMIT = 100
		self.MIN_LIMIT = 0
		self.counter = 50
		self.mutex = QMutex()

	def add(self):
		self.mutex.lock()
		if self.counter < self.MAX_LIMIT:
			self.counter = self.counter + 1
		self.mutex.unlock()

	def substract(self):
		self.mutex.lock()
		if self.counter > self.MIN_LIMIT:
			self.counter = self.counter - 1
		self.mutex.unlock()

	def printStatus(self,thread):
		print “Counter:”,self.counter,” - Thread:”,id(thread)

		if self.counter > self.MAX_LIMIT+1 or self.counter < self.MIN_LIMIT:
			print "Stopping Threads, Max Surpassed, Not Thread Safe. Last Thread:",id(thread)
			sys.exit()

class MutexLockerTestSubject(QObject):
	'''
	Class that attemps to synchronize thread
 	access to its add(),substract() methods with
	the QMutexLocker object.
	'''
	def __init__(self):
		QObject.__init__(self)
		self.MAX_LIMIT = 100
		self.MIN_LIMIT = 0
		self.counter = 50
		self.mutex = QMutex()

	def add(self):
		#VIP: DO NOT MAKE mutexLocker an attribute of your class.
		#other wise it won't be destroyed and the lock will never be released.
		mutexLocker = QMutexLocker(self.mutex)
		if self.counter < self.MAX_LIMIT:
			self.counter = self.counter + 1

	def substract(self):
		mutexLocker = QMutexLocker(self.mutex)
		if self.counter > self.MIN_LIMIT:
			self.counter = self.counter - 1

	def printStatus(self,thread):
		print “Counter:”,self.counter,” - Thread:”,id(thread)

		if self.counter > self.MAX_LIMIT+1 or self.counter < self.MIN_LIMIT:
			print "Stopping Threads, Max Surpassed, Not Thread Safe. Last Thread:",id(thread)
			sys.exit()

class AdderWorker(QThread):
	def __init__(self, mutexTestObject):
		self.mutexTestObject = mutexTestObject
		QThread.__init__(self)

	def run(self):
		while(True):
			self.mutexTestObject.add()
			self.mutexTestObject.printStatus(self)

class SubstractorWorker(QThread):
	def __init__(self, mutexTestObject):
		self.mutexTestObject = mutexTestObject
		QThread.__init__(self,mutexTestObject)

	def run(self):
		while(True):
			self.mutexTestObject.substract()
			self.mutexTestObject.printStatus(self)

if __name__ == "__main__":
	USE_MUTEX_LOCKER = True #switch this to use regular mutexes vd QMutexLocker
	app = QApplication(sys.argv)
	mutexTestObject = MutexTestSubject() if not USE_MUTEX_LOCKER else MutexLockerTestSubject()

	adderThread  = AdderWorker(mutexTestObject)
	substracterThread = SubstractorWorker(mutexTestObject)

	adderThread.start()
	substracterThread.start()

	sys.exit(app.exec_())

FrostWire has been reviewed by CNET

Wednesday, November 21st, 2007

On November 20th, FrostWire gets a very positive review by CNET’s download.com, and makes it to the home page of download.com as the Killer Download of the Day

Click here to read

Their review makes us very happy, at the same time, it pushes us to include new killer features that LimeWire may not be able to have in the near future, however if you follow LimeWire’s code base, it seems they’re working hard to release a web based Music Store that will be included on an embedded browser inside their client, probably in the fashion of the online iTunes store, but probably powered by P2P (we hope, if they stick to their p2p philosophy and hopefully without DRM so that files can be shared or bought, at least this worked beautifully for Radiohead).

It’d probably be a smart move by the LimeWire store to include the possibility to buy their music from outside their site (with commissions on sales of course), that way, other music sites could trigger purchases based on search, as well as other p2p clients such as FrostWire.

The Internet Quiz - I scored 96% and you?

Tuesday, November 20th, 2007

free dating sites

Philadelphia Dating

Episodio 071 - ANDROID pone a Symbian a temblar

Thursday, November 15th, 2007

Agrega a iTunes Agreganos a tu iTunes | Descarga en MP3 | Suscribete a este podcast | Skypeanos

Dale Play aqui mismo



Guarda TODOS tus archivos gratis en MyBloop.com!



Noticias

Patrocinantes de este Episodio

MacKinando.com