I have a twisted / PATIP application (except for other things) connecting to a group of remote resources when the user closes the window so I want to close all the connections, if not possible, forcibly.
The problem is that unless I close the connection, it seems that the reactor is not going to be alive anymore for me to do this.
Here is my app code:
# Create apps and connect twisted / Qt reactors app Q Qplication (sys.argv) qtreactor .qt4reactor.install () #Shutdown Turn off when the window closes @ defer.inline callback def stop (): Print "=" * 40, "Closing connection ..." yield off () Print "=" * 40 "Off." Print "=" * 40, "Stop Reactor ..." Reactor.stop () Print "=" * 40, "Paused." APC Connect (App, Signal ("Last Window Blocked"), Stop) Reactor. Rune Retron (RC) = APEXAC_ () Exit (RC) And here's a down Version is for connection connection: Printed "connection is closing #% s"% connection yield threads. Defer.inline callback def close connection () bar / cleaning% s "% connection") print "connection closed. "
The first print statement is reached, and the command is executed, but I do not get the second, nor do I go for multiples of the loop also. < P> Is my analysis correct? Is this problem that the reactor is already below, so I never hear from the thread. DeferToThread? Or is there any other problem? Besides, how can I fix this?
Thanks, Jonathan
t know that When the signal is lastWindowClosed () , even if it seems to fire early, before reactor closes (preventing you from doing what you want to do), I'm sure PyQt does not know what to do with your returned code by the> Stop function. This means that the shutdown process will proceed to Marily, while trying to run your asynchronous cleanup code It is possible that your network will shut down Do not ever will be to finish the GUI shutdown before. So, Riactor.adsistm Iventtrigr ( 'first', 'off', pause) using . I do not know whether it will go a bit earlier or a while later than lastWindowClosed () , but it will run quickly that the reactor will still be usable, and It will focus on deferred your function returns. In fact, the shutdown will be postponed until a deferred fire occurs. It gives you the need to clean yourself at all times. From this, you should not threads.deferToThread (popen ("/ foo / bar / cleanup% s"%) connection)) : < Ul> Not the result of calling the colable, you should be able to call at deferToThread In writing, your code runs popin in the reactor thread and the file object to call the thread (Which can not be understood at all) Mixing threads and hair processes iffy you do not have the time with it Cal can, I do not know. reactor. Spondus process will let you run a child process without threads, without threads, and without worrying about mixing threads and also see the procedures twisted.internet.utils.getProcessOutput If you see < Not all attributes of code> spawnProcess (which you do not see).
Comments
Post a Comment