List Info

Thread: Cloning threading.py using proccesses




Cloning threading.py using proccesses
user name
2006-10-10 14:28:31
You may already know about a similar project a friend of
mine (hi,
Steffen!) did a few years ago called Python Object Sharing
(POSH).  This
was however unix specific and relied on fork and SYSV IPC
iirc.  I see
he has a SF projectpage here:

http://poshmodule.
sourceforge.net/

(doesn't seem to be a lot of activity there, though).

Best regards

__ 
Audun Ostrem Nordal     tel: +41.22.76.74427
CERN IT/IS
1211 Geneve 23
Switzerland 

> -----Original Message-----
> From: python-dev-bounces+audun=cern.chpython.org 
> [mailto:python-dev-bounces+audun=cern.chpython.org] On 
> Behalf Of Richard Oudkerk
> Sent: Monday, October 09, 2006 1:59 PM
> To: python-devpython.org
> Subject: [Python-Dev] Cloning threading.py using
proccesses
> 
> I am not sure how sensible the idea is, but I have had
a 
> first stab at writing a module processing.py which is a
near 
> clone of threading.py but uses processes and sockets
for 
> communication.  (It is one way of avoiding the GIL.)
> 
> I have tested it on unix and windows and it seem to
work pretty well.
> (Getting round the lack of os.fork on windows is a bit 
> awkward.) There is also another module
dummy_processing.py 
> which has the same api but is just a wrapper round
threading.py.
> 
> Queues, Locks, RLocks, Conditions, Semaphores and some
other 
> shared objects are implemented.
> 
> People are welcome to try out the tests in
test_processing.py 
> contained in the zipfile.  More information is included
in 
> the README file.
> 
> As a quick example, the code
> 
> .   from processing import Process, Queue,
ObjectManager
> .
> .   def f(token):
> .       q = proxy(token)
> .       for i in range(10):
> .           q.put(i*i)
> .       q.put('STOP')
> .
> .   if __name__ == '__main__':
> .       manager = ObjectManager()
> .       token = manager.new(Queue)
> .       queue = proxy(token)
> .
> .       t = Process(target=f, args=[token])
> .       t.start()
> .
> .       result = None
> .       while result != 'STOP':
> .           result = queue.get()
> .           print result
> .
> .       t.join()
> 
> is not very different from the normal threaded
equivalent
> 
> .   from threading import Thread
> .   from Queue import Queue
> .
> .   def f(q):
> .       for i in range(10):
> .           q.put(i*i)
> .       q.put('STOP')
> .
> .   if __name__ == '__main__':
> .       queue = Queue()
> .
> .       t = Thread(target=f, args=[queue])
> .       t.start()
> .
> .       result = None
> .       while result != 'STOP':
> .           result = queue.get()
> .           print result
> .
> .       t.join()
> 
> Richard
> 
_______________________________________________
Python-Dev mailing list
Python-Devpython.org
ht
tp://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: http://mail.python.org/mailman/options/p
ython-dev/nessto%40sharedlog.com
[1]

about | contact  Other archives ( Real Estate discussion Medical topics )