Steven,

On Sun, 2012-05-13 at 10:22 +1000, Steven D'Aprano wrote:
> carlo locci wrote:
> > Hello All,
> > I've started to study python a couple of month ago(and I truly love it :)),
> > however I'm having some problems understanding how to modify a sequential
> > script and make it multithreaded (I think it's because I'm not used to
> > think in that way), 
> 
> No, that's because multithreading and parallel processing is hard.

Shared memory multithreading may be hard due to locks, semaphores,
monitors, etc., but concurrency and parallelism need not be hard. Using
processes and message passing, using dataflow, actors or CSP,
parallelism and concurrency is far more straightforward. Not easy,
agreed, but then programming isn't easy.

> > as well as when it's best to use it(some say that
> > because of the GIL I won't get any real benefit from threading my script).
> 
> That depends on what your script does.
> 
> In a nutshell, if your program is limited by CPU processing, then using 
> threads in Python won't help. (There are other things you can do instead, 
> such 
> as launching new Python processes.)

The GIL in Python is a bad thing for parallelism. Using the
multiprocessing package or concurrent.futures gets over the problem.
Well sort of, these processes are a bit heavyweight compared to what can
be achieved on the JVM or with Erlang.

> If your program is limited by disk or network I/O, then there is a 
> possibility 
> you can speed it up with threads.

Or better still use an event based system, cf Twisted.

[...]
> 

-- 
Russel.
=============================================================================
Dr Russel Winder      t: +44 20 7585 2200   voip: sip:russel.win...@ekiga.net
41 Buckmaster Road    m: +44 7770 465 077   xmpp: rus...@winder.org.uk
London SW11 1EN, UK   w: www.russel.org.uk  skype: russel_winder

Attachment: signature.asc
Description: This is a digitally signed message part

_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Reply via email to