to py or not to py ?

Tom Plunket gamedev at fancy.org
Wed Jun 28 18:06:40 EDT 2006


Carl J. Van Arsdall wrote:

> Because of the GIL only one thread can actually run at a time.

I've recently been wondering about this, since in the work I do, a lot
of time is spent doing disk I/O.  So if I want the UI to remain
responsive, I could spawn an IO thread to handle requests, and do a
pretty simple "just whack new requests onto the queue" without locks
since I'm guaranteed to not have the IO thread read at the same time
as the requestor thread?

...what exactly constitutes an atomic operation in Python, anyway?

e.g.

class IoThread:
   # ...

   # called from the other thread...
   def RequestFile(self, name):
      self.fileQueue.append(name)

   # called during the IO thread
   def GetNextFile(self);
      next = self.fileQueue[0]
      self.fileQueue.pop(0)
      return next

?
-tom!



More information about the Python-list mailing list