Re: Re: New stackless proposal
Paul Prescod <[email protected]>
| Newsgroups | gmane.comp.lang.prothon.user |
|---|---|
| Message-ID | <[email protected]> |
I don't have time today to really understand all of that stuff
especially given that I don't use threads that much.
One thing jumped out at me as really weird and unPythonic (and probably
unProthonic).
O>> def thread1(seconds): # (*12)
... print 'thread1 is running'
... Sleep(seconds * 1.0)
... print 'thread1 is stopping'
...
O>> thread1 = OSThread(thread1)
<OSThread:41fc3a2:uninitialized>
O>> thread1 = thread1(10) # call thread1 to "arm" it(*1,5)
O>> thread1
<OSThread:41fc3a2:armed>
O>> thread1.start() # these two could have been thread1(10).start()
thread1 is running
O>> thread1
<OSThread:41fc3a2:running>
O>>
thread1 is stopping
The name thread1 is bound 3 times. As a coding style this is questionable.
I notice you use a wrapping model here rather than an inheritance model
(opposite of properties). OSThread looks like a wrapper.
I don't understand why you use call_ to arm a thread and then rebind the
name. If the call_ function mutates the underlying object then why do
you have to rebind the name? If it creates a new object then why rebind
it to the same name? Here's what I would expect:
def myfunc(seconds):
print 'thread1 is running'
Sleep(seconds * 1.0)
print 'thread1 is stopping'
thread1 = OSThread(myfunc)
thread1.params = [10]
thread1.start()
If I want many similar OSThreads I guess I would do it this way:
thread1 = OSThread(myfunc)
thread2 = thread1.copy()
thread1.params = [10]
thread2.params = [20]
thread1.start()
thread2.start()
Paul Prescod