[Twisted-Python] Proposed change to API for threadtask.

I'd like to change twisted.internet.threadtask.schedule from def schedule(function, args=[], kwargs={}): to be def schedule(function, *args, **kwargs): Any objections? -- ______ __ __ _____ _ _ | ____ | \_/ |_____] |_____| |_____| |_____ | | | | @ t w i s t e d m a t r i x . c o m http://twistedmatrix.com/users/glyph

Glyph Lefkowitz wrote:
I'd like to change twisted.internet.threadtask.schedule from
def schedule(function, args=[], kwargs={}):
to be
def schedule(function, *args, **kwargs):
Fine by me - Python 2.0 makes them almost interchangeable anyway. Anyone else have suggested API changes? this is the time to do it since right now only I am using this code :)

I am trying to get a threaded twisted server to run on windows (Windows2000 SP3) and having some issues. There is an assert in threadable.py in init(): def init(with_threads): global threaded, _to_be_synched, dispatcher, dispatch, Waiter, dispatchOS print "Threadable init", with_threads if threaded == with_threads: return assert threaded is None threaded = with_threads that always asserts whether I pass "-t" to twistd or not. It seems that requireInit() gets called before init() so the code: def requireInit(): global threaded if threaded is None: init(0) is always run to initialize the global "threaded" to zero. If i take out that "assert threaded in None" it seems to initialize correctly on the "second" time through. But, in internet.main the global "waker" is never initialized as installWaker() is never called. I think that is because threadable.threaded was initialized as 0 the "first" time through when it was called by requireInit() and the code: if threadable.threaded: installWaker() in internet.main.py skips the installWaker() call. Anyone else tried running a threaded server on windows?

threaded initialization stuff twisted.internet.main.py is not working for me on windows. I propose we put all threaded initialization into a method of twisted.internet.main and have it called from threadable.init() in one place. This would include: installWaker() delayeds.append(threadtask.theScheduler) how about internet.main.enableThreading() which would do the work that is currently in installWaker and set up the delayed scheduler? On my machine with that change and some minor changes to threading.init() I can run both threaded and non-threaded code on windows. -----Original Message----- From: twisted-python-admin@twistedmatrix.com [mailto:twisted-python-admin@twistedmatrix.com]On Behalf Of Sean Riley Sent: Tuesday, August 21, 2001 3:23 PM To: twisted-python@twistedmatrix.com Subject: [Twisted-Python] threading on windows? I am trying to get a threaded twisted server to run on windows (Windows2000 SP3) and having some issues. There is an assert in threadable.py in init(): def init(with_threads): global threaded, _to_be_synched, dispatcher, dispatch, Waiter, dispatchOS print "Threadable init", with_threads if threaded == with_threads: return assert threaded is None threaded = with_threads that always asserts whether I pass "-t" to twistd or not. It seems that requireInit() gets called before init() so the code: def requireInit(): global threaded if threaded is None: init(0) is always run to initialize the global "threaded" to zero. If i take out that "assert threaded in None" it seems to initialize correctly on the "second" time through. But, in internet.main the global "waker" is never initialized as installWaker() is never called. I think that is because threadable.threaded was initialized as 0 the "first" time through when it was called by requireInit() and the code: if threadable.threaded: installWaker() in internet.main.py skips the installWaker() call. Anyone else tried running a threaded server on windows? _______________________________________________ Twisted-Python mailing list Twisted-Python@twistedmatrix.com http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python

Sean Riley wrote:
threaded initialization stuff twisted.internet.main.py is not working for me on windows.
I propose we put all threaded initialization into a method of twisted.internet.main and have it called from threadable.init() in one place.
Yes, but threaded can be used without internet.main's event loop, so it shouldn't depend on it.
This would include: installWaker() delayeds.append(threadtask.theScheduler)
how about internet.main.enableThreading() which would do the work that is currently in installWaker and set up the delayed scheduler?
note that threading has to be initialized before threadtask is imported, so that it will be synchronized. Can you explain why the current code doesn't work in Windows?

actually i have a counter question that is "how the hell does this work on Linux at all?" during startup, threadable.init() is called twice - once by internet.main calling requireInit() which passes zero and once by twistd which passes zero or one if "-t" was specified. the first time through, the global threaded is set to zero. the second time through, the "assert threaded is None" in threadable.init() should always fail as threaded is not None, it is now zero. This assert failing causes threadable.threaded to get left as zero and the initialization of installing the waker and scheduler never gets done. -----Original Message----- From: twisted-python-admin@twistedmatrix.com [mailto:twisted-python-admin@twistedmatrix.com]On Behalf Of Itamar Sent: Tuesday, August 21, 2001 5:14 PM To: twisted-python@twistedmatrix.com Subject: Re: [Twisted-Python] threading on windows? Sean Riley wrote:
threaded initialization stuff twisted.internet.main.py is not working for me on windows.
I propose we put all threaded initialization into a method of twisted.internet.main and have it called from threadable.init() in one place.
Yes, but threaded can be used without internet.main's event loop, so it shouldn't depend on it.
This would include: installWaker() delayeds.append(threadtask.theScheduler)
how about internet.main.enableThreading() which would do the work that is currently in installWaker and set up the delayed scheduler?
note that threading has to be initialized before threadtask is imported, so that it will be synchronized. Can you explain why the current code doesn't work in Windows? _______________________________________________ Twisted-Python mailing list Twisted-Python@twistedmatrix.com http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python

On Tue, Aug 21, 2001 at 05:40:26PM -0500, Sean Riley wrote:
actually i have a counter question that is "how the hell does this work on Linux at all?"
It doesn't, far as I can tell. Mea culpa -- I added an 'import main' to the top of twistd as part of the addition of twisted.persisted.styles.Versioned, but it should not be imported until _after_ the initial threadable.init. I will check in a fix in a few minutes. I think we need some acceptance tests that test threading agressively. -- ______ __ __ _____ _ _ | ____ | \_/ |_____] |_____| |_____| |_____ | | | | @ t w i s t e d m a t r i x . c o m http://twistedmatrix.com/users/glyph

Glyph Lefkowitz wrote:
On Tue, Aug 21, 2001 at 05:40:26PM -0500, Sean Riley wrote:
actually i have a counter question that is "how the hell does this work on Linux at all?"
It doesn't, far as I can tell.
And I never encountered this since I don't use twistd. Maybe write a test that uses a client that sends data and expects to get it back, and then test by using it against echoserv and echoserv_threaded?

Yay! We like pictures. :-) Jason -----Original Message----- From: twisted-python-admin@twistedmatrix.com [mailto:twisted-python-admin@twistedmatrix.com]On Behalf Of Sean Riley Sent: Thursday, August 23, 2001 4:34 PM To: twisted-python@twistedmatrix.com Subject: [Twisted-Python] twisted network objects diagram I drew a picture!
participants (5)
-
Glyph Lefkowitz
-
Itamar
-
Itamar Shtull-Trauring
-
Jason L. Asbahr
-
Sean Riley