[Python-checkins] python/dist/src/Doc/tut tut.tex,1.245,1.246

rhettinger at users.sourceforge.net rhettinger at users.sourceforge.net
Mon Aug 16 07:11:06 CEST 2004


Update of /cvsroot/python/python/dist/src/Doc/tut
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv30341

Modified Files:
	tut.tex 
Log Message:
Minor improvements to the threading introduction:

* Expand the example to show a join.

* Mention the use case of I/O running concurrent with a computational
  thread.

* Be a tad more forceful about recommending Queue over other approaches
  to synchonization.

* Eliminate discussion around having a single interpreter.  This is a
  more advanced discussion that belongs in the library reference and
  in a section on extending and embedding.



Index: tut.tex
===================================================================
RCS file: /cvsroot/python/python/dist/src/Doc/tut/tut.tex,v
retrieving revision 1.245
retrieving revision 1.246
diff -C2 -d -r1.245 -r1.246
*** tut.tex	9 Aug 2004 14:06:58 -0000	1.245
--- tut.tex	16 Aug 2004 05:11:04 -0000	1.246
***************
*** 4869,4878 ****
  
  Threading is a technique for decoupling tasks which are not sequentially
! dependent.  Python threads are driven by the operating system and run
! in a single process and share memory space in a single interpreter.
  
! Threads can be used to improve the responsiveness of applications that
! accept user input while other tasks run in the background.  The
! following code shows how the high level
  \ulink{\module{threading}}{../lib/module-threading.html} module can run
  tasks in background while the main program continues to run:
--- 4869,4878 ----
  
  Threading is a technique for decoupling tasks which are not sequentially
! dependent.  Threads can be used to improve the responsiveness of
! applications that accept user input while other tasks run in the
! background.  A related use case is running I/O in parallel with
! computations in another thread.
  
! The following code shows how the high level
  \ulink{\module{threading}}{../lib/module-threading.html} module can run
  tasks in background while the main program continues to run:
***************
*** 4892,4897 ****
              print 'Finished background zip of: ', self.infile
  
!     AsyncZip('mydata.txt', 'myarchive.zip').start()
!     print 'The main program continues to run'
  \end{verbatim}
  
--- 4892,4901 ----
              print 'Finished background zip of: ', self.infile
  
!     background = AsyncZip('mydata.txt', 'myarchive.zip')
!     background.start()
!     print 'The main program continues to run in foreground.'
!     
!     background.join()    # Wait for the background task to finish
!     print 'Main program waited until background was done.'
  \end{verbatim}
  
***************
*** 4902,4912 ****
  
  While those tools are powerful, minor design errors can result in
! problems that are difficult to reproduce.  A simpler and more robust
! approach to task coordination is concentrating all access to a resource
  in a single thread and then using the
  \ulink{\module{Queue}}{../lib/module-Queue.html} module to feed that
! thread with requests from other threads.  Applications that use
  \class{Queue} objects for inter-thread communication and coordination
! tend to be easier to design, more readable, and more reliable.
  
  
--- 4906,4916 ----
  
  While those tools are powerful, minor design errors can result in
! problems that are difficult to reproduce.  So, the preferred approach
! to task coordination is to concentrate all access to a resource
  in a single thread and then using the
  \ulink{\module{Queue}}{../lib/module-Queue.html} module to feed that
! thread with requests from other threads.  Applications using
  \class{Queue} objects for inter-thread communication and coordination
! are easier to design, more readable, and more reliable.
  
  



More information about the Python-checkins mailing list