[Tutor] Questions about threads

Andrei Kulakov ak@silmarill.org
Tue, 28 Aug 2001 08:29:09 -0400

On Tue, Aug 28, 2001 at 02:18:54PM +0200, A wrote:
> Hi,
> Can anybody please answer my questions?
> 1. In my application  I need one function to run in threads. The 
> number of threads is chosen by user and numbers of threads can 
> not be higher at one time. 
> This function writes to a file also.How can I prevent other threads 
> from writting to this file when the file is open by another thread ?

I never done this, but I guess you should 'lock' the file, that is, set a
global var file_locked to 1, then open file, write to it, then set
file_locked to 0. There may be some gotchas here, I'm not sure if this is

> 2. How can one process control another? For example: my 
> program tries to connect to a server over phone.  I want  to cancel 
> dial up connection if there is timeout. How can that be done in 
> Python?

Through global variables, like in above example.


> Thank you very much for help.
> Ladislav
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor

Cymbaline: intelligent learning mp3 player - python, linux, console.
get it at: cy.silmarill.org