473,471 Members | 2,005 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Timer

Does Python have a timer mechanism? i.e. an "after 500 milliseconds, run
this bit of code" sort of thing?
Jul 18 '05 #1
31 26579
Derek Fountain wrote:
Does Python have a timer mechanism? i.e. an "after 500 milliseconds, run
this bit of code" sort of thing?

http://www.python.org/Doc/lib/module-sched.html

but you should perhaps also look into twisteds event-based framework who
does it even better. www.twistedmatrix.com

Jul 18 '05 #2

"Noen" <no***********@na.no> wrote in message news:zp*********************@juliett.dax.net...
Derek Fountain wrote:
Does Python have a timer mechanism? i.e. an "after 500 milliseconds, run
this bit of code" sort of thing?

http://www.python.org/Doc/lib/module-sched.html


The above link doesn't work. This does:

http://www.python.org/doc/current/lib/module-sched.html
--
Georgy Pruss
E^mail: 'ZDAwMTEyMHQwMzMwQGhvdG1haWwuY29t\n'.decode('base6 4')
Jul 18 '05 #3
> > > Does Python have a timer mechanism? i.e. an "after 500 milliseconds, run
this bit of code" sort of thing?


why not just use the time.sleep() function ?

Jul 18 '05 #4
[Derek Fountain]
Does Python have a timer mechanism? i.e. an "after 500 milliseconds, run
this bit of code" sort of thing?


Like this?

#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
import threading

def hello():
print "hello, world"

t = threading.Timer(30.0, hello)
t.start() # after 30 seconds, "hello, world" will be printed
#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

Timers start a new thread of execution.

More info from here

http://www.python.org/doc/current/li...r-objects.html

HTH,

--
alan kennedy
-----------------------------------------------------
check http headers here: http://xhaus.com/headers
email alan: http://xhaus.com/mailto/alan
Jul 18 '05 #5
Dave Harrison wrote:
> > Does Python have a timer mechanism? i.e. an "after 500 milliseconds,
> > run this bit of code" sort of thing?


why not just use the time.sleep() function ?


Because that stops the thread. I want things to continue, and then be
interrupted in order to execute a bit of code. Tcl has the 'after' command:

after 5000 { set disabled 0 }

The script carries on, and after 5 seconds whatever is being done gets
interrupted in order to run a bit of script - in this case set a variable
turning off a disablement of some sort. This makes it trivial to implement
"disable this feature for 5 seconds" kinds of logic.

I can't find anything like that in Python.
Jul 18 '05 #6
Alan Kennedy wrote:
[Derek Fountain]
Does Python have a timer mechanism? i.e. an "after 500 milliseconds, run
this bit of code" sort of thing?


Like this?
http://www.python.org/doc/current/li...r-objects.html


That looks like what I'm after, yes. I haven't looked into threads since
they've represented trouble in every other language I've used. But I'll
have a look into their implementation in Python and see if they're any more
usable here...

Thanks.
Jul 18 '05 #7
At 9:04 PM +0800 27/10/03, Derek Fountain wrote:
Dave Harrison wrote:
> > Does Python have a timer mechanism? i.e. an "after 500 milliseconds,
> > run this bit of code" sort of thing?


why not just use the time.sleep() function ?


Because that stops the thread. I want things to continue, and then be
interrupted in order to execute a bit of code. Tcl has the 'after' command:

after 5000 { set disabled 0 }

The script carries on, and after 5 seconds whatever is being done gets
interrupted in order to run a bit of script - in this case set a variable
turning off a disablement of some sort.


Wow, that must make your scripts so much more interesting to debug ;)

Anthony
--
----------------------------------------------------
HyPEraCtiVE? HeY, WhO aRE YoU cALliNg HypERaCtIve?!
aB*****@wEStNeT.cOm.aU
----------------------------------------------------

Jul 18 '05 #8
At 09:21 PM 10/26/2003, Derek Fountain wrote:
Does Python have a timer mechanism? i.e. an "after 500 milliseconds, run
this bit of code" sort of thing?


Check out the sched and time modules.

Bob Gailer
bg*****@alum.rpi.edu
303 442 2625
---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.525 / Virus Database: 322 - Release Date: 10/9/2003

Jul 18 '05 #9
In article <3f***********************@freenews.iinet.net.au >,
Derek Fountain <no****@hursley.ibm.com> wrote:
Dave Harrison wrote:
> > Does Python have a timer mechanism? i.e. an "after 500 milliseconds,
> > run this bit of code" sort of thing?


why not just use the time.sleep() function ?


Because that stops the thread.


Check out the threading module. In particular, the threading.Timer class.
Jul 18 '05 #10
In article <ma************************************@python.org >,
Anthony Briggs <ab*****@westnet.com.au> wrote:
Jul 18 '05 #11
[Cameron Laird]
This thread is really about asynchronous or concurrent
processing,
I really don't have time to post to the level of detail I would like,
but I had to put forward a couple of thoughts.
I claim, and I further claim we really don't
have *any* satisfying model for coding those.
I think you might get some disagreement from the Twisted, Medusa and
ZServer people. And possibly see a slanging match erupt on whose
design is best....
Threading
is a quagmire (everyone agree?),
Definitely. Sometimes.

I think threads are really a useful abstraction for programmers who
are learning to deal with developing servers for the first time. And
threads fulfill their function very well, to a point.

But they have fundamental scalability problems: The C10K problem
illustrates this well: Surely it should be possible for a modern
computer, with giga-everything (!), to serve 10,000 clients
simultaneously?

http://www.kegel.com/c10k.html

To go beyond the performance limits imposed by the resource-hogging
threads (OMG, > 1MB of core on some platforms!), it's necessary to
move to a different concurrency mechanism, such as coroutines, which
represents "tasklets" much more efficiently.

But event-based concurrency models suffer from a fundamental
limitation: it is more difficult to spread work across multiple
processors. CPython, to some degree, lets event-based developers off
the hook, because the presence of the GIL allows them to not address
the problem, because it wouldn't achieve anything anyway.....

And the patchy support for SSL in asynch frameworks is another
fundamental problem.

Another point in favour of threads: On a multi-processor box, the
thread abstraction generally "automagically" gives you free migration
to other processors. You (generally) don't have to change a line of
your code: the underlying [OS|VM] takes care of it.
and our guild has demonstrated only marginally more
reliability in working with,
say, co-routines, chords, continuations, and so on. For
my money, the event-oriented model behind the [after]
above is at least as robust as any other.
FWIW, I think that Java has a very nice model for asynchronous IO,
with all "selectors" being thread-safe, so that "selectables" that are
ready for IO can be processed in another thread, i.e. potentially on
another processor, thus giving the best of both worlds.

http://java.sun.com/j2se/1.4.2/docs/...e-summary.html
Among other frailties, I hold a grudge against the aca-
demic world that it hasn't shown more leadership in this
matter.
Googling for "'high performance' asynchronous server" shows that both
Academia and Industry are certainly not short of powerpoint-ware on
the subject......
I'll summarize: validation of event-oriented designs
implemented with [after] and similar mechanisms, is at
worst no more difficult than validation of the corre-
sponding thread-based designs. Concurrency is hard to
get right, at least with our current understanding.


My €0,02: Generators (and, by extension, coroutines) will be python's
greatest advance in simplifying writing event-based server
architectures: resumable functions are a honking great idea.

regards,

--
alan kennedy
-----------------------------------------------------
check http headers here: http://xhaus.com/headers
email alan: http://xhaus.com/mailto/alan
Jul 18 '05 #12
[Cameron Laird]
This thread is really about asynchronous or concurrent
processing,
I really don't have time to post to the level of detail I would like,
but I had to put forward a couple of thoughts.
I claim, and I further claim we really don't
have *any* satisfying model for coding those.
I think you might get some disagreement from the Twisted, Medusa and
ZServer people. And possibly see a slanging match erupt on whose
design is best....
Threading
is a quagmire (everyone agree?),
Definitely. Sometimes.

I think threads are really a useful abstraction for programmers who
are learning to deal with developing servers for the first time. And
threads fulfill their function very well, to a point.

But they have fundamental scalability problems: The C10K problem
illustrates this well: Surely it should be possible for a modern
computer, with giga-everything (!), to serve 10,000 clients
simultaneously?

http://www.kegel.com/c10k.html

To go beyond the performance limits imposed by the resource-hogging
threads (OMG, > 1MB of core on some platforms!), it's necessary to
move to a different concurrency mechanism, such as coroutines, which
represents "tasklets" much more efficiently.

But event-based concurrency models suffer from a fundamental
limitation: it is more difficult to spread work across multiple
processors. CPython, to some degree, lets event-based developers off
the hook, because the presence of the GIL allows them to not address
the problem, because it wouldn't achieve anything anyway.....

And the patchy support for SSL in asynch frameworks is another
fundamental problem.

Another point in favour of threads: On a multi-processor box, the
thread abstraction generally "automagically" gives you free migration
to other processors. You (generally) don't have to change a line of
your code: the underlying [OS|VM] takes care of it.
and our guild has demonstrated only marginally more
reliability in working with,
say, co-routines, chords, continuations, and so on. For
my money, the event-oriented model behind the [after]
above is at least as robust as any other.
FWIW, I think that Java has a very nice model for asynchronous IO,
with all "selectors" being thread-safe, so that "selectables" that are
ready for IO can be processed in another thread, i.e. potentially on
another processor, thus giving the best of both worlds.

http://java.sun.com/j2se/1.4.2/docs/...e-summary.html
Among other frailties, I hold a grudge against the aca-
demic world that it hasn't shown more leadership in this
matter.
Googling for "'high performance' asynchronous server" shows that both
Academia and Industry are certainly not short of powerpoint-ware on
the subject......
I'll summarize: validation of event-oriented designs
implemented with [after] and similar mechanisms, is at
worst no more difficult than validation of the corre-
sponding thread-based designs. Concurrency is hard to
get right, at least with our current understanding.


My €0,02: Generators (and, by extension, coroutines) will be python's
greatest advance in simplifying writing event-based server
architectures: resumable functions are a honking great idea.

regards,

--
alan kennedy
-----------------------------------------------------
check http headers here: http://xhaus.com/headers
email alan: http://xhaus.com/mailto/alan

Jul 18 '05 #13
Python standard library offers a 'Timer' class as part
of its threading library.

The documentation should be reachable at
http://www.python.org/doc/current/li...r-objects.html

It is easy to create your own timer objects by using
python threads.

Here is a sample code for the same. It is a working
code, and creates a custom timer class with a maximum
timeout, which calls the function again and again until
it times out. It is different from the standard timer
which calls its target function just once.

----------------<snip>-----<snip>--------------------
from threading import Thread
import time

class ModifiedTimer(Thread):

def __init__(self, interval, maxtime, target):
self.__interval = interval
self.__maxtime = maxtime
self.__tottime = 0.0
self.__target = target
self.__flag = 0
Thread.__init__(self, None, 'mytimer', None)

def run(self):

while self.__flag==0:
time.sleep(self.__interval)
self.__target()
self.__tottime += self.__interval

if self.__tottime >= self.__maxtime:
print 'Timing out...'
self.end()

def end(self):
self.__flag=1

class MyTimer:

def __init__(self):
self.__interval = 5.0

def __timerfunc(self):
print 'Hello, this is the timer function!'

def make_timer(self, interval):
self.__interval = interval
self.__timer = ModifiedTimer(self.__interval, 60.0, self.__timerfunc)
self.__timer.start()

if __name__=="__main__":
t=MyTimer()
t.make_timer(10.0)

------------------<snip>-----------<snip>---------------
HTH

-Anand Pillai
Bob Gailer <bg*****@alum.rpi.edu> wrote in message news:<ma************************************@pytho n.org>...
At 09:21 PM 10/26/2003, Derek Fountain wrote:
Does Python have a timer mechanism? i.e. an "after 500 milliseconds, run
this bit of code" sort of thing?


Check out the sched and time modules.

Bob Gailer
bg*****@alum.rpi.edu
303 442 2625

--

Jul 18 '05 #14
In article <3F***************@hotmail.com>,
Alan Kennedy <al****@hotmail.com> wrote:
[Cameron Laird]
This thread is really about asynchronous or concurrent
processing,
I really don't have time to post to the level of detail I would like,
but I had to put forward a couple of thoughts.

This is mostly a "me, too" follow-up. I decided
to post it, though, if only to ensure
I claim, and I further claim we really don't
have *any* satisfying model for coding those.


I think you might get some disagreement from the Twisted, Medusa and
ZServer people. And possibly see a slanging match erupt on whose
design is best....

that Twisted et al. don't feel abused. I am VERY
fond of Twisted, Medusa, and Zope, and have even
written an (unpublished, still) article on their
concurrency management. I, also, won't go into
detail now; I just want to make clear that I think
they're great, and was excluding them only for
categorical reasons.
Jul 18 '05 #15
> Wow, that must make your scripts so much more interesting to debug ;)

:o) I suppose it depends how you use it. It's implemented using event
processing, so nothing really happens concurrently, even on SMP boxes. So
it's not as confusing as it could be with a threaded model.

Jul 18 '05 #16
> > why not just use the time.sleep() function ?

Because that stops the thread. I want things to continue, and then be
interrupted in order to execute a bit of code. Tcl has the 'after' command:


*chuckle* must've missed that start of the thread ;-) never saw
the word threading.

Deadlock-is-a-pain-to-debug-ingly yours
Dave

Jul 18 '05 #17
At 11:59 AM -0500 27/10/03, Cameron Laird wrote:
In article <ma************************************@python.org >,
Anthony Briggs <ab*****@westnet.com.au> wrote:
>>after 5000 { set disabled 0 }

The script carries on, and after 5 seconds whatever is being done gets
interrupted in order to run a bit of script - in this case set a variable
turning off a disablement of some sort.
>Wow, that must make your scripts so much more interesting to debug ;)


You probably think you wrote something uncontroversial.


No, I wrote something that I consider true. I'd consider that after
command to be on a par with Fortran's(?) COME FROM statement in terms
of being able to create subtle bugs.
I take this question rather seriously, as it turns out.

Scripts that are "easy to debug" make for an apt focus.
This thread is really about asynchronous or concurrent
processing, I claim, and I further claim we really don't
have *any* satisfying model for coding those. Threading
is a quagmire (everyone agree?), and our guild has demon-
strated only marginally more reliability in working with,
say, co-routines, chords, continuations, and so on. For
my money, the event-oriented model behind the [after]
above is at least as robust as any other.


Yes, that's what I said - only with fewer words :)

Anthony
--
----------------------------------------------------
HyPEraCtiVE? HeY, WhO aRE YoU cALliNg HypERaCtIve?!
aB*****@wEStNeT.cOm.aU
----------------------------------------------------

Jul 18 '05 #18
Anthony Briggs wrote:
...
No, I wrote something that I consider true. I'd consider that after
command to be on a par with Fortran's(?) COME FROM statement in terms
Intercal. Lawrence Clark's 1973 article about "comefrom" in Fortran
was satire (just as all of Intercal is).
of being able to create subtle bugs.


Note that, in Python, you have that 'after' available any time
you're running a Tkinter GUI: any Tkinter widget has an 'after'
method that takes a delay (in milliseconds), a callable object,
and optionally some arguments, and schedules the callable to
be called with those arguments after that delay.

It works a charm, btw.

my money, the event-oriented model behind the [after]
above is at least as robust as any other.


Yes, that's what I said - only with fewer words :)


I thought you were arguing AGAINST the 'after' functionality,
and therefore against event-driven programming...?!

Surely, if I do have a program that's architected around
responding to asynchronous events (as GUIs invariably are,
as network programming can be with asyncore or Twisted),
the ability to explicitly schedule an event (thus a callback)
for some time in the future is no problem - just handy!
Alex

Jul 18 '05 #19
Alan Kennedy wrote:
...
And the patchy support for SSL in asynch frameworks is another
fundamental problem.
Hmmm, what's wrong with Twisted+pyOpenSSL...? Seems to work fine...
Another point in favour of threads: On a multi-processor box, the
thread abstraction generally "automagically" gives you free migration
to other processors. You (generally) don't have to change a line of
your code: the underlying [OS|VM] takes care of it.


*blink*? Uh, doesn't that depend on how you choose to have your
threads communicate with each other? The most Pythonic solution
is generally to have threads communicate via Queue instances. Can
you point me to a "cross-process Queue" class for Linux and Windows?

Not a rhetoric question -- I'd LIKE to be able to scale things up that
way, but see some problems with translating typical Queue use idioms,
particularly in a cross-platform way, to cross-process:
-- N1 client-threads posting workrequests to Q and N2 worker-threads
peeling workrequests off Q and working on them;
-- a workrequest including a reference to the Queue instance on
which the worker-thread is going to post the response/result
Alex

Jul 18 '05 #20
At 11:14 AM +0000 28/10/03, Alex Martelli wrote:
Anthony Briggs wrote:
...
No, I wrote something that I consider true. I'd consider that after
command to be on a par with Fortran's(?) COME FROM statement in terms
Intercal. Lawrence Clark's 1973 article about "comefrom" in Fortran
was satire (just as all of Intercal is).


Ah. I just read the article at
<http://www.fortran.com/fortran/come_from.html>. Most enlightening ;)
Note that, in Python, you have that 'after' available any time
you're running a Tkinter GUI: any Tkinter widget has an 'after'
method that takes a delay (in milliseconds), a callable object,
and optionally some arguments, and schedules the callable to
be called with those arguments after that delay.

It works a charm, btw.


I'll take your word for it. It sounds like a recipe for a lot of hair
pulling to me. What happens if there's some part of your code that
you don't want interrupted? eg. database commits, file access, any
sort of time critical stuff, that sort of thing. Is there a way to
switch it off?
>>my money, the event-oriented model behind the [after]
above is at least as robust as any other.


Yes, that's what I said - only with fewer words :)


I thought you were arguing AGAINST the 'after' functionality,
and therefore against event-driven programming...?!


Perhaps I was taking his words a little too literally. As far as I
can tell with threads, etc, they're little better than voodoo. So the
after statement is at least as robust, even if it's a complete
horror...

Anthony
--
----------------------------------------------------
HyPEraCtiVE? HeY, WhO aRE YoU cALliNg HypERaCtIve?!
aB*****@wEStNeT.cOm.aU
----------------------------------------------------

Jul 18 '05 #21
In article <yc********************@news1.tin.it>,
Alex Martelli <al***@aleax.it> wrote:
Jul 18 '05 #22
[Alan Kennedy]
And the patchy support for SSL in asynch frameworks is another
fundamental problem.
[Alex Martelli]
Hmmm, what's wrong with Twisted+pyOpenSSL...? Seems to work fine...
I haven't used that particular combination.

I was going to followup my own post to mention that my statement was
not in any way meant to be slight to any of the providers of python
SSL. For example, Ng Pheng Siong has put a lot of work into getting
M2Crypto SSL working in non-blocking mode.

My understanding is that using SSL in non-blocking mode is problematic
because SSL-level packets can trigger readiness notification on an SSL
socket when in fact there is no application-level data available.

Here is a link that discusses the problem

http://www.openssl.org/support/faq.html#PROG9

I honestly don't know if all of the asynch models implemented in
python address this problem, and would be happy to be enlightened
and/or proven completely wrong if they have.

Java nio has this problem, which will be addressed in java 1.5

http://www.itworld.com/nl/java_sec/09142001/

[Alan Kennedy] Another point in favour of threads: On a multi-processor box, the
thread abstraction generally "automagically" gives you free migration
to other processors. You (generally) don't have to change a line of
your code: the underlying [OS|VM] takes care of it.


[Alex Martelli] *blink*? Uh, doesn't that depend on how you choose to have your
threads communicate with each other?
There is assumption behind my statement: that the underlying [OS|VM]
also maps the memory space of threads running on different processors
so that they coincide, and all objects are shared between threads as
if they were local to the "process" containing the threads.

If I use a Queue.Queue in jython, (AFAICT) the different threads can
be running on different processors, and the Queue.Queue will work just
fine as a synch mechanism.
The most Pythonic solution
is generally to have threads communicate via Queue instances. Can
you point me to a "cross-process Queue" class for Linux and Windows?
I'd love to. However, python's Queue.Queue class doesn't work across
processes, only across threads. But those threads could still
potentially be running on multiple processors in the same box (see
above re jython).

It'd be nice if we could have a Queue.Queue style IPC mechanism that
worked between processes, and that could be included in the set of
"selectables" for an event-driven framework. Without copious
serialization/pickling. I have stated that several times in this
forum.
Not a rhetoric question -- I'd LIKE to be able to scale things up that
way, but see some problems with translating typical Queue use idioms,
particularly in a cross-platform way, to cross-process:
-- N1 client-threads posting workrequests to Q and N2 worker-threads
peeling workrequests off Q and working on them;
-- a workrequest including a reference to the Queue instance on
which the worker-thread is going to post the response/result


I was interested to read about TupleSpaces from a recent post. Though
I haven't looked into TupleSpaces in detail, I can imagine that
there's lots of de/serialization going on.

Lastly, another area which seems to have patchy support across
operating systems is that of non-blocking file-locks, which would be
required for many event-driven apps.

regards,

--
alan kennedy
-----------------------------------------------------
check http headers here: http://xhaus.com/headers
email alan: http://xhaus.com/mailto/alan
Jul 18 '05 #23
In article <ma************************************@python.org >,
Anthony Briggs <ab*****@westnet.com.au> wrote:
Jul 18 '05 #24
Anthony Briggs wrote:
...
I'll take your word for it. It sounds like a recipe for a lot of hair
pulling to me. What happens if there's some part of your code that
you don't want interrupted? eg. database commits, file access, any
sort of time critical stuff, that sort of thing. Is there a way to
switch it off?
Event-driven processing, AKA asynchronous processing, is not
pre-emptive: on the contrary, it relies on each event handler
(callback) terminating reasonably promptly and thus returning
to the main loop. Hmmm -- ever programmed a GUI...?

I thought you were arguing AGAINST the 'after' functionality,
and therefore against event-driven programming...?!


Perhaps I was taking his words a little too literally. As far as I
can tell with threads, etc, they're little better than voodoo. So the


Threads are best kept in their place by keeping them well separated
with Queue instances, although I wouldn't be surprised to hear that
the blood of a black roster strangled at midnight is also effective.
after statement is at least as robust, even if it's a complete
horror...


Nope -- the callback is done in the same thread that requested
it, so "thread separation" is not at issue.
Alex

Jul 18 '05 #25
Cameron Laird wrote:
In article <yc********************@news1.tin.it>,
Alex Martelli <al***@aleax.it> wrote:
.
.
.
Note that, in Python, you have that 'after' available any time
you're running a Tkinter GUI: any Tkinter widget has an 'after'
method that takes a delay (in milliseconds), a callable object,
and optionally some arguments, and schedules the callable to
be called with those arguments after that delay.

It works a charm, btw.

.
.
.
I want to refine Alex' description: it's possible to
use after with only the slenderest connection to a
Tkinter GUI. You can "import Tkinter", and exploit
after(), without ever having to make Tkinter widgets
or windows visible on the screen.


and I'll further refine yours: "as long as you run
Tkinter's mainloop". Yes, you can hide Tkinter's root
window and still run its mainloop (I think you have
to be explicit about it though:-), as long as you don't
need any of the normal processing flow used by most
non-GUI applications (including other event-driven apps
that don't use Tkinter's mainloop -- e.g., network ones
that use asyncore or select). And the .after callback
will be able to get into play only if other callbacks
(presumably also from .after, if you have no GUI) return
reasonably promptly.

In short, I doubt using Tkinter just for the sake of
getting .after makes much sense -- you're probably at
least as well off with the much lighter-weight scheduler
module, in that case. (OTOH, if it IS possible to
give fileobjects to Tkinter to cause callbacks when
they're ready, as it is in Tcl/Tk, then using Tkinter
w/o GUI may indeed be easier than merging e.g scheduler
and select -- it depends... but last time I checked I
saw no way to get the "callback on file activity" from
Tkinter as I could back when I used Tcl/Tk...).
Alex

Jul 18 '05 #26
Alex Martelli <al***@aleax.it> writes:
In short, I doubt using Tkinter just for the sake of
getting .after makes much sense -- you're probably at
least as well off with the much lighter-weight scheduler
module, in that case. (OTOH, if it IS possible to
give fileobjects to Tkinter to cause callbacks when
they're ready, as it is in Tcl/Tk, then using Tkinter
w/o GUI may indeed be easier than merging e.g scheduler
and select -- it depends... but last time I checked I
saw no way to get the "callback on file activity" from
Tkinter as I could back when I used Tcl/Tk...).


Huh? _tkinter.createfilehandler() is there (pyrepl uses it). I think
only on Unix, but I think that also applies to Tcl_CreateFileHandler,
so that's not much of a surprise.

Cheers,
mwh

--
First time I've gotten a programming job that required a drug
test. I was worried they were going to say "you don't have
enough LSD in your system to do Unix programming". -- Paul Tomblin
-- http://home.xnet.com/~raven/Sysadmin/ASR.Quotes.html
Jul 18 '05 #27
Alan Kennedy <al****@hotmail.com> wrote in message news:<3F***************@hotmail.com>...
My understanding is that using SSL in non-blocking mode is problematic
because SSL-level packets can trigger readiness notification on an SSL
socket when in fact there is no application-level data available.

Here is a link that discusses the problem

http://www.openssl.org/support/faq.html#PROG9


Twisted does the right thing and makes sure the user doesn't have to
worry about this. Using SSL is just as easy as using TCP in Twisted.

There are other issues with event loops, like the fact the RSA
handshake is very expensive so you want to run it in another thread.
If Twisted ever has performance issues due to this I'll probably
change the code to do just that, move the handshake stage to a
threadpool.
Jul 18 '05 #28
[Alan Kennedy]
My understanding is that using SSL in non-blocking mode is problematic
because SSL-level packets can trigger readiness notification on an SSL
socket when in fact there is no application-level data available.

[Itamar Shtull-Trauring] Twisted does the right thing and makes sure the user doesn't have to
worry about this. Using SSL is just as easy as using TCP in Twisted.

There are other issues with event loops, like the fact the RSA
handshake is very expensive so you want to run it in another thread.
If Twisted ever has performance issues due to this I'll probably
change the code to do just that, move the handshake stage to a
threadpool.


Thanks for that Itamar.

IMHO, another good solution to the SSL/Non-Blocking IO problem might
be to run stunnel (www.stunnel.org) to do the SSL decode, and then
forward the decrypted requests to an non-SSL asynch server. Although I
have never tried this.

Stunnel can use OpenSSL, which means that support for hardware crypto
accelerators comes for free, etc, etc.

regards,

--
alan kennedy
-----------------------------------------------------
check http headers here: http://xhaus.com/headers
email alan: http://xhaus.com/mailto/alan
Jul 18 '05 #29
Michael Hudson wrote:
...
and select -- it depends... but last time I checked I
saw no way to get the "callback on file activity" from
Tkinter as I could back when I used Tcl/Tk...).


Huh? _tkinter.createfilehandler() is there (pyrepl uses it). I think
only on Unix, but I think that also applies to Tcl_CreateFileHandler,
so that's not much of a surprise.


I could have sworn I got "callbacks on file activity" cross-platform
when I used Tcl/Tk, but maybe it's just a memory grown rosy with age.
Alex

Jul 18 '05 #30
Derek Fountain a écrit :
Does Python have a timer mechanism? i.e. an "after 500 milliseconds, run
this bit of code" sort of thing?


The sched module in the standard library may be what you're looking for.

--
Alexandre Fayolle
LOGILAB, Paris (France).
http://www.logilab.com http://www.logilab.fr http://www.logilab.org
Développement logiciel avancé - Intelligence Artificielle - Formations
Jul 18 '05 #31
Alex Martelli <al***@aleax.it> writes:
Michael Hudson wrote:
...
and select -- it depends... but last time I checked I
saw no way to get the "callback on file activity" from
Tkinter as I could back when I used Tcl/Tk...).


Huh? _tkinter.createfilehandler() is there (pyrepl uses it). I think
only on Unix, but I think that also applies to Tcl_CreateFileHandler,
so that's not much of a surprise.


I could have sworn I got "callbacks on file activity" cross-platform
when I used Tcl/Tk, but maybe it's just a memory grown rosy with age.


Well, maybe. I haven't been near a Windows system in months & months
and have never used Tcl/Tk in isolation, so please don't be surprised
when I'm wrong about Tcl on windows :-)

Cheers,
mwh

--
Make this IDLE version 0.8. (We have to skip 0.7 because that
was a CNRI release in a corner of the basement of a government
building on a planet circling Aldebaran.)
-- Guido Van Rossum, in a checkin comment
Jul 18 '05 #32

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: HL | last post by:
I am using VS 2005 Beta - C# Problem: The Timer fires a few milliseconds before the actual Due-Time Let's say a timer is created in the following manner: System.Threading.Timer m_timer = null;...
2
by: John David Thornton | last post by:
I've got a Windows Service class, and I put a System.Threading.Timer, and I've coded it as shown below. However, when I install the service and then start it in MMC, I get a peculiar message: ...
12
by: Gina_Marano | last post by:
I have created an array of timers (1-n). At first I just created windows form timers but I read that system timers are better for background work. The timers will just be monitoring different...
8
by: KnighT | last post by:
I have a .net service that runs a System.Threading.Timer. The delegate points to the function that the service should execute when the timer elapses. Problem: The timer is not ticking. I have...
8
by: =?Utf-8?B?RGF2ZSBCb29rZXI=?= | last post by:
I have a Timer that I set to go off once a day, but it frequently fails! In order to debug I would like to be able to check, at any moment, whether the Timer is enabled and when it will next...
11
by: Hotrod2000 | last post by:
I'm quite new to programming but I'm having problems getting a timer to work in visual studio.net I've created a timer on a form, enabled it and then typed the following code (from the mdsn...
16
by: Peter Oliphant | last post by:
Note that although this involves SAPI, it is more a question about Timers and event handlers. I wrote a Speech Recognize handler (SAPI), and put some code in it to enable a Timer. It would not...
11
by: Anil Gupte/iCinema.com | last post by:
When I use this Dim instance As New Timer I get the error: Error 1 Overload resolution failed because no accessible 'New' accepts this number of arguments. Yet, in the help section for...
3
by: Steve | last post by:
Hi All I am using VB.net 2008 and use timer controls within my applications Question Does the code in a Timer control.tick event run on a different thread to the main Application thread (UI...
1
by: Eran Hefer | last post by:
With SharePoint timer jobs you can create & execute processes on a daily / hourly / minutely basis. After deployment, the timer job definition executes your custom code. The easiest (and more...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.