[Twisted-Python] [twisted-python] a problem about reactor

Hi all, I'm puzzled by this code: # -*- coding: utf-8 -*- from twisted.web.client import reactor f = open("test1.txt","w") f.write("html") reactor.run() Then it won't write anything into test1.txt. When I deleted "reactor.run()", it will write contents. It is interesting but I don't know why the reactor blocks file writing. Best regards, Joson

Hi! On Mon, Mar 29, 2010 at 11:04:25PM +0800, Joson Mandaro wrote:
Then it won't write anything into test1.txt. When I deleted "reactor.run()", it will write contents. It is interesting but I don't know why the reactor blocks file writing.
Try the same code in the interpreter and check the content of the file:
f=open("test.txt", "w") # creates an empty file f.write("html") # file is still empty f.close() # content is written to the file
Python is nice enough to close the file when it reaches the end of the script. But this never happens when the last statement is reactor.run(). Regards, Albert -- DI Albert Brandl Weiermayer Solutions GmbH | http://www.weiermayer.com 4813 Altmünster | Abteistraße 12 | Austria | Fon: +43(0)720 70 30 14 | Fax: +43 (0) 7612 88081
participants (2)
-
Albert Brandl
-
Joson Mandaro