[Twisted-Python] Concurrent data access with select() safe?

Tommi Virtanen tv at twistedmatrix.com
Wed Aug 14 00:43:59 EDT 2002


On Wed, Aug 14, 2002 at 03:37:09AM +0800, Mukhsein Johari wrote:
> On Wednesday 14 August 2002 02:28, Matt Campbell wrote:
> > completion, as if it's always running in a critical section. (This
> > is also why no blocking system calls should be performed except in
> > the main loop itself.)
> 
> Sorry for being so dense but, what do you mean by this? Does file access count 
> as blocking (my gut says "yes")? How would you handle that? In the twisted 
> system in general, from what I understand of it, classes are instantiated to 
> handle client requests. If those instances access files or in-memory data 
> objects it is conceivable that two instances might be accessing the same data 
> / file, right? But from you you say, this is fine since there is only one 
> thread. But what do you mean by blocking calls should only be run in the main 
> loop? Is the above (file access) blocking? And is it, as the case stated 
> above "within the main loop"?

	You shouldn't do anything that takes a long time;
	events won't be processed while the single thread
	runs your long operation.

	Matt said "(This is also why no blocking system calls should
	be performed except in the main loop itself.)"; well, most
	system calls "block", but the idea is to not run ones that
	can block indefinitely -- e.g. send(). Those are run
	by the mainloop in a non-blocking mode.

-- 
tv@{{hq.yok.utu,havoc,gaeshido}.fi,{debian,wanderer}.org,stonesoft.com}
double a,b=4,c;main(){for(;++a<2e6;c-=(b=-b)/a++);printf("%f\n",c);}




More information about the Twisted-Python mailing list