New to threads. How do they work?
Dermot Doran
dppdoran at gmail.com
Thu Jul 20 03:35:05 EDT 2006
Hi
I think the answer to your last question is that the threading module
provides a high level interface (i.e. easier to use) to the thread module.
The thread module is very low-level. Any threaded python scripts I have
written (not expert) have used the threading module which is, in my opinion,
a very clean easy to use module. Just takes a bit of hacking with to get
used to.
Cheers!!
Dermot.
On 19 Jul 2006 23:53:22 -0700, gel <geli at tasmail.com> wrote:
>
>
> Dennis Lee Bieber wrote:
>
> > On 19 Jul 2006 19:08:12 -0700, "gel" <geli at tasmail.com> declaimed the
> > following in comp.lang.python:
> >
> > > import thread
> > >
> > Step one... Skip the thread module and use threading module
> instead.
> >
> > > def create():
> > >
> > > pythoncom.CoInitialize()
> > > c = wmi.WMI()
> > > while 1 :
> > >
> > > print "watching creation"
> > > watcher = c.watch_for(notification_type="Creation",
> > > wmi_class="Win32_Process", delay_secs=1)
> >
> > I don't know WMI, but is that delay a real sleep operation, or a
> > polling loop?
> >
> > And either could be a problem if they hold the GIL -- preventing
> > anything else from running until they return...
> >
> > >
> > > thread.start_new_thread(create(),())
> > > thread.start_new_thread(delete(),())
> >
> > At the very least, I suggest commenting out the COM and WMI calls
> --
> > test threads that ONLY print output and do a time.sleep(1). That should
> > be sufficient to see if the threads themselves are being started.
> > --
> > Wulfraed Dennis Lee Bieber KD6MOG
> > wlfraed at ix.netcom.com wulfraed at bestiaria.com
> > HTTP://wlfraed.home.netcom.com/
> > (Bestiaria Support Staff: web-asst at bestiaria.com)
> > HTTP://www.bestiaria.com/
>
> Thanks alot for your help. I had tried using threading with a
> different setup in the function side but did not get success. I think
> that I have winner now. Thanks again. What follows is the what I have
> working so far. And another question why do you prefer to us threading
> and thread?
>
> import wmi
> import pythoncom
> import threading
>
> def create():
>
> pythoncom.CoInitialize()
> c = wmi.WMI()
> while 1 :
>
> print "watching creation"
> watcher = c.watch_for(notification_type="Creation",
> wmi_class="Win32_Process", delay_secs=1)
> print watcher()
>
> def delete():
>
> pythoncom.CoInitialize()
> d = wmi.WMI()
> while 1 :
> print "watching deletion"
> watcher = d.watch_for(notification_type="Deletion",
> wmi_class="Win32_Process", delay_secs=1)
> print watcher()
>
> import threading
> threading.Thread(target=create).start()
> threading.Thread(target=delete).start()
>
> Cheers
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20060720/4fd65291/attachment.html>
More information about the Python-list
mailing list