Re: use var to form name of object
Marc 'BlackJack' Rintsch wrote: > In <[EMAIL PROTECTED]>, gel wrote: > > > Yeah I am still getting my head around things... not exactly sure what > > you where saying about the globals, but this works > > > > > > global k > > k = 5 > > class foo: > > > > def wow(self, n): > > global k > > k += n > > return k > > > > > > f=foo() > > f.wow(55) > > The first ``global`` does nothing. ``global`` at module level makes no > sense. And the snippet could be easily written without assigning to > global names from within a function/method: > > k = 5 > class Foo: > def wow(self, n): > return k + n > > f = Foo() > k = f.wow(55) > > Ciao, > Marc 'BlackJack' Rintsch Ah yes, thanks for that Marc -- http://mail.python.org/mailman/listinfo/python-list
New to threads. How do they work?
Hi all I am attempting to understand threads to use in a network app which I am writing. The part that I am going to use threads on is run on the clients/workstations. I will monitor all starting and ending processes. Below is what I have been doing. It looks like only the first thread is starting. Can someone explain a basic example of how threads work and are implemented, what is better to use threading or thread module, and what am I doing wrong in the example below. I know I have asked a lot of questions, any help/direction would be appreciated. Thanks import wmi import pythoncom import thread 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() thread.start_new_thread(create(),()) thread.start_new_thread(delete(),()) -- http://mail.python.org/mailman/listinfo/python-list
Re: New to threads. How do they work?
Dennis Lee Bieber wrote: > On 19 Jul 2006 19:08:12 -0700, "gel" <[EMAIL PROTECTED]> 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. > -- > WulfraedDennis Lee Bieber KD6MOG > [EMAIL PROTECTED] [EMAIL PROTECTED] > HTTP://wlfraed.home.netcom.com/ > (Bestiaria Support Staff: [EMAIL PROTECTED]) > 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
What would be the best way to run python client in the background
Hi I have written a python client server app that keeps an eye on processes starting and ending on a client and makes decision on what to do based on information from the server end. I want to run the client end of the app more or less invisibly (no console) on the XP clients when ever a users logs on. What would be the best way to get this done? A bit more info on the purpose of the app... it is to act as a licence server, where we have a limited number of licences for software and the software installed on all PCs. The app will only allow a pre defined number of clients to run the software at any one time. -- http://mail.python.org/mailman/listinfo/python-list
Re: What would be the best way to run python client in the background
Tim Golden wrote: > [gel] > > | I have written a python client server app [...] > | I want to run the client end of the app more or less invisibly > | (no console) on the XP clients when ever a users logs on. > > You say "when[]ever a user logs on" but does this app > need to be run on a per-user basis? Or could it run all > the time -- ie as a Windows Service -- and do enough to > determine which user is logged on when it needed to? Yes at the moment the user name is set when the program starts, but it is no problem to stick that further down program in the loop that watches processes start and finish. > > The normal way is to run a Win32 service. There are several > posts on the subject around the Python and Python-Win32 > mailing lists / newsgroups. The alternative is to set something > to run when any user logs in to run without a window. Again, > there are posts on the subject, including one I seem to remember > from Robin Becker, which tell how to do this kind of thing. Yes running the client as a service seems to be the way to go. I have had a bit of a look at the py2exe way of doing it, but have not got my head around it yet. What would be your preferred way of creating a service for an XP client? > > Let us know if you can't find anything which seems to > fit the bill. > > TJG > > > This e-mail has been scanned for all viruses by Star. The > service is powered by MessageLabs. For more information on a proactive > anti-virus service working around the clock, around the globe, visit: > http://www.star.net.uk > -- http://mail.python.org/mailman/listinfo/python-list
Re: What would be the best way to run python client in the background
Tim Golden wrote: > | > [gel] > | > > | > | I have written a python client server app [...] > | > | I want to run the client end of the app more or less invisibly > | > | (no console) on the XP clients when ever a users logs on. > > While this isn't answering the question you first > asked, might I suggest an alternative approach? > Obviously, I'm working from no more than the sketch > you gave of your app and its requirements, but might > it be worth turning the problem on its head, and > using WMI? > > Advantages: > > 1) WMI will -- almost certainly -- already be running on your > target machines. No need to install your own service. > > 2) WMI has a fair range of mechanisms for determining > what processes are starting, stopping, etc. and for > manipulating them remotely. > > 3) You can, at least in theory, access any number of machines > from a central server, and with a bit of judicious threading > or looping, you should be able to generate a fair bit of resilience > to machine dropouts etc. > > Disadvantages: > > 1) What you're doing may be far more complex than you've > outlined, requiring a local service per target machine > for other reasons. > > 2) You may have already invested some amount of time and > effort in developing an app which does what you want. > > 3) I may have entirely misunderstood what you're trying > to do in any case. > > If you're interested and want a code sample, let me know. > If you're not, that's fine. > > TJG > Hi Tim Thanks for your suggestion, I have just got to read the post now and appolagise to you and the others who have replied to my post for the big gap. I will have a read today and get back to you. -- http://mail.python.org/mailman/listinfo/python-list
Re: What would be the best way to run python client in the background
Roger Upole wrote: > You can use the Task Scheduler to run a script at login. > It's not as robust as creating a service, but it's much less > work. > > Roger > OK thanks Roger I will have a bit a look at that option. It is fairly important for the solution to be robust, but this maybe enough. Cheers > "gel" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > > Hi > > I have written a python client server app that keeps an eye on > > processes starting and ending on a client and makes decision on what to > > do based on information from the server end. I want to run the client > > end of the app more or less invisibly (no console) on the XP clients > > when ever a users logs on. What would be the best way to get this > > done? A bit more info on the purpose of the app... it is to act as a > > licence server, where we have a limited number of licences for software > > and the software installed on all PCs. The app will only allow a pre > > defined number of clients to run the software at any one time. > > -- http://mail.python.org/mailman/listinfo/python-list
Re: What would be the best way to run python client in the background
Ravi Teja wrote: > gel wrote: > > Hi > > I have written a python client server app that keeps an eye on > > processes starting and ending on a client and makes decision on what to > > do based on information from the server end. I want to run the client > > end of the app more or less invisibly (no console) on the XP clients > > when ever a users logs on. What would be the best way to get this > > done? A bit more info on the purpose of the app... it is to act as a > > licence server, where we have a limited number of licences for software > > and the software installed on all PCs. The app will only allow a pre > > defined number of clients to run the software at any one time. > > To run a python script without a console - use *.pyw extension. > > But from what you stated you perhaps don't want to do this. Whether you > deploy this check as a service (through py2exe for example) or a > straight script, the users may simply kill it if they want to bypass > the check. Plus it is not common to use a seperate persistant process > to check for licenses. A better way is to incorporate the check > directly into the process of the software. The reason for the a seperate persistant check is because it will be used to enable software to be installed in whole lab of PCs but only allow a predifined number to run the software at any time one time. And then when a user stop using the software a licence will become available to for someone else on the same or another PC to use the software. The reason that the process of the software being check is not used is because it will be used for software written by other people. I hope this makes what and why a little clearer. Let me know if you think that I have misunderstoood you. -- http://mail.python.org/mailman/listinfo/python-list
Re: What would be the best way to run python client in the background
Tim Golden wrote: > | > [gel] > | > > | > | I have written a python client server app [...] > | > | I want to run the client end of the app more or less invisibly > | > | (no console) on the XP clients when ever a users logs on. > > While this isn't answering the question you first > asked, might I suggest an alternative approach? > Obviously, I'm working from no more than the sketch > you gave of your app and its requirements, but might > it be worth turning the problem on its head, and > using WMI? > > Advantages: > > 1) WMI will -- almost certainly -- already be running on your > target machines. No need to install your own service. > > 2) WMI has a fair range of mechanisms for determining > what processes are starting, stopping, etc. and for > manipulating them remotely. > > 3) You can, at least in theory, access any number of machines > from a central server, and with a bit of judicious threading > or looping, you should be able to generate a fair bit of resilience > to machine dropouts etc. > > Disadvantages: > > 1) What you're doing may be far more complex than you've > outlined, requiring a local service per target machine > for other reasons. > > 2) You may have already invested some amount of time and > effort in developing an app which does what you want. > > 3) I may have entirely misunderstood what you're trying > to do in any case. > > If you're interested and want a code sample, let me know. > If you're not, that's fine. > > TJG > Yes Tim I would be interested in seeing a code sample of how you would approach this using a central server using wmi. I am using wmi at the moment too, but on the client side, then pyro to keep a central record of what was being run where. So the client side watches for starting praocesses, when one is found it checks the pyro object on the server to see if the process is one that is being watched and if it is, check to see if the allowed limit of PCs running that process has ben reached. If the limit has not been reached the client marks the pyro object on the server to indicate that another PC is running that piece of software. If the limit has been reached the client side kills the process and pops a dialogue box up stating that there are no more licences available for that piece of software and to try again later. The reverse happens when a process is stopped. If the process is one that is being watched and that client has a licence book out for that software (checked with the MAC address) the number of PCs running that pieces of software, which is stored in the pyro object on the server decreased by one. The thing that springs to mind with using a method where a central server is using wmi, is the question of if a lot of polling of the remote client would be needed to know when a new process starts or stops and if this would be heavy on the network and server? -- http://mail.python.org/mailman/listinfo/python-list
Re: What would be the best way to run python client in the background
Tim Golden wrote: > | Tim Golden wrote: > | > | > [gel] > | > > | > | I have written a python client server app [...] > | > | I want to run the client end of the app more or less invisibly > | > | (no console) on the XP clients when ever a users logs on. > > [Tim G] > | > The normal way is to run a Win32 service. There are several > | > posts on the subject around the Python and Python-Win32 > | > mailing lists / newsgroups. The alternative is to set something > | > to run when any user logs in to run without a window. Again, > | > there are posts on the subject, including one I seem to remember > | > from Robin Becker, which tell how to do this kind of thing. > > [gel] > | Yes running the client as a service seems to be the way to go. I have > | had a bit of a look at the py2exe way of doing it, but have not got my > | head around it yet. What would be your preferred way of creating a > | service for an XP client? > > I've always coded pretty much from scratch, reusing a tried-and-trusted > skeleton and fitting things in. That said, I've never had to put > together > a service that was anything more than lightweight. The attached template > I > culled from someone's webpage, can't remember where I'm afraid. I > believe > people have had success in using py2exe to create a service but I > haven't > tried it myself. > > Hopefully more experienced service-writers will chime in with coherent > advice. You might also try the python-win32 mailing list, since not > everyone who reads that reads this I imagine. > > TJG > Can I give you a look at the client side and ask for a suggestion as how best to plug this into the template that you have supplied The attempts that I made failed to start without much in the way of error messages. Any suggestion to do with my python style that you have would be appreciated too. # Import needed modules import EasyDialogs import wmi import pythoncom import threading import time import Pyro.core import Pyro.naming, Pyro.core from Pyro.errors import NamingError # locate the NS locator = Pyro.naming.NameServerLocator() print 'Searching Name Server...', ns = locator.getNS() # resolve the Pyro object print 'finding object' try: URI=ns.resolve('test') print 'URI:',URI except NamingError,x: print 'Couldn\'t find object, nameserver says:',x raise SystemExit # make and instance of Pyro object o = Pyro.core.getProxyForURI(URI) #instance of wmi and get mac address of enabled NIC c = wmi.WMI() for interface in c.Win32_NetworkAdapterConfiguration (IPEnabled=1): # print interface.Description, interface.MACAddress for ip_address in interface.IPAddress: mac = interface.MACAddress # put current time into var current_time colItems = c.ExecQuery("SELECT UserName FROM Win32_ComputerSystem") for objItem in colItems: if objItem.UserName != None: usr_name = str(objItem.UserName) print "UserName: " + usr_name # assign the dictionary object that o.r_l() returns to d_licence_numbers d_licence_numbers = o.r_l() # So I can see how many licences are available for each piece of software print d_licence_numbers print d_licence_numbers # Define the create class that watches for new processes to start def diag(mesg): EasyDialogs.Message(mesg) def create(): global usr_name pythoncom.CoInitialize() c = wmi.WMI() while 1 : current_time = time.time() d_clnt = {'MAC':mac, 'time':current_time, 'usr_name': usr_name} print d_clnt print "watching creation" watcher = c.watch_for(notification_type="Creation", wmi_class="Win32_Process", delay_secs=1) proc = watcher() name = proc.Name if d_licence_numbers.has_key(name): print "Process being watched = " + name if len(o.r_d()[name]) != 0: li = o.r_d()[name] registered = False for i in li: print usr_name print i['usr_name'] if mac == i['MAC'] or i['usr_name'] == usr_name: print "Already in there" registered = True if registered != True: for i in li: #ps_id = ps_li.index(sw) if len(o.r_d()[name]) < o.r_l()[name]: o.a_d(name, d_clnt) print "There is a license avialabl
I would like write some data recovery software
I would like to write some data recovery software as a learning thing. The sort of thing that you would use to recover data from a currupt HDD or floppy etc. I would like to be pointed in the right direction as far as modules to use and suggested approaches. -- http://mail.python.org/mailman/listinfo/python-list
Re: I would like write some data recovery software
Dennis Lee Bieber wrote: > On 17 Oct 2006 20:18:40 -0700, "gel" <[EMAIL PROTECTED]> declaimed > the following in comp.lang.python: > > > I would like to write some data recovery software as a learning thing. > > The sort of thing that you would use to recover data from a currupt HDD > > or floppy etc. I would like to be pointed in the right direction as > > far as modules to use and suggested approaches. > > Uh... this is highly OS dependent... You need to be able to do > direct RAW disk sector addressing; something that OSs don't really like > to give to applications. You also need very good documentation of the > file system (and the only file system I know well enough to navigate at > that level is one I haven't used in over a decade -- the file system > used by the Amiga, which was a hashed-head, multiple linked list > scheme). > -- > WulfraedDennis Lee Bieber KD6MOG > [EMAIL PROTECTED] [EMAIL PROTECTED] > HTTP://wlfraed.home.netcom.com/ Yes, OK I guess NTFS would be of most interest to me. From the research I have been doing it may be that it is a fairly in depth undertaking and possibly not such a good project considering my knowledge of NTFS and python. I will have bit more of a look about. Thanks > (Bestiaria Support Staff: [EMAIL PROTECTED]) > HTTP://www.bestiaria.com/ -- http://mail.python.org/mailman/listinfo/python-list
Re: I would like write some data recovery software
Laurent Pointal wrote: > gel a écrit : > > I would like to write some data recovery software as a learning thing. > > The sort of thing that you would use to recover data from a currupt HDD > > or floppy etc. I would like to be pointed in the right direction as > > far as modules to use and suggested approaches. > > > > Once you get a way to access the bytes to recover... the Hachoir library > can be interresting as a model to map structures on these data. > > http://hachoir.org/ > > > A+ > > Laurent. Cheers, I am having a bit of look at it now -- http://mail.python.org/mailman/listinfo/python-list
use var to form name of object
Hi I would like to pass a variable in and use it as part of a name of an object, something like below, where I pass the variable software into the function and use it as part of the name of the object so that I can append to it using the other vairables. Any suggestions? def a_d(self,software,mac,time,extra): global d_software d_software.software.append([mac,time,extra]) -- http://mail.python.org/mailman/listinfo/python-list
Re: use var to form name of object
gel wrote: > Hi > I would like to pass a variable in and use it as part of a name of an > object, something like below, where I pass the variable software into > the function and use it as part of the name of the object so that I can > append to it using the other vairables. Any suggestions? > > > def a_d(self,software,mac,time,extra): > global d_software > d_software.software.append([mac,time,extra]) I sorted it out -- http://mail.python.org/mailman/listinfo/python-list
Re: use var to form name of object
Bruno Desthuilliers wrote: > gel wrote: > > gel wrote: > > > > > >>Hi > >>I would like to pass a variable in and use it as part of a name of an > >>object, something like below, where I pass the variable software into > >>the function and use it as part of the name of the object so that I can > >>append to it using the other vairables. Any suggestions? > >> > >> > >>def a_d(self,software,mac,time,extra): > >>global d_software > >>d_software.software.append([mac,time,extra]) > > > > > > I sorted it out > > > Then do a favour to other persons facing the same problem : share your > solution. As a side effect, you'll also have your code checked by lot of > confirmed Python programmer !-) > > -- > bruno desthuilliers > python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for > p in '[EMAIL PROTECTED]'.split('@')])" OK, I would love to, the reason I did not was for fear of wasting peoples time with basic stuff... I ended up doing it a bit differently what I am doing is using pyro to make a package that can be run on PCs to control how many PC on a network are running a piece of software,the function def a_d(self,software,mac): global d_software d_software[software][0].append(mac) return d_software is in the module on the pyro server. When this object is used on the client it adds the clients mac address to the dictionary list. When another client is runs the software being watched it checks how many are already running by counting the number of mac addresses already in there. If the number of PCs already running the software is below the number allowed, which is set in the pyro module it is allowed to continue to run it. If the limit has been reached the client software kills the software, Below is the client and the pyro module... Client import wmi import time import Pyro.core c = wmi.WMI() o=Pyro.core.getAttrProxyForURI('PYRONAME://:Default.test') for interface in c.Win32_NetworkAdapterConfiguration (IPEnabled=1): # print interface.Description, interface.MACAddress for ip_address in interface.IPAddress: mac = interface.MACAddress mac = 1 current_time = time.time() sw = "notepad.exe" #o.a_d(sw, mac, current_time, "Maybe More Extra Stuff too") while 1: time.sleep(1.0) ps_li=[] for process in c.Win32_Process (): #print process.ProcessId, process.Name ps_li += [process.Name] if sw in ps_li: if len(o.r_d()[sw][0]) != 0: if mac in o.r_d()[sw][0]: print "Already in there" else: #ps_id = ps_li.index(sw) if len(o.r_d()[sw][0]) < o.r_l()[sw]: o.a_d(sw, mac) print "There are some" print o.r_d() else: print "There are none" for process in c.Win32_Process (): if process.Name == "notepad.exe": print process.ProcessId, process.Name result = process.Terminate () print process.Name +" has been killed" else: o.a_d(sw, mac) print "First in" else: print sw + " not running" pyro module class testclass: import wmi import time global d_software global l_notepad global d_licence_numbers d_licence_numbers = {"notepad.exe":1, "Adobe":1} l_notepad =[] d_software = {"notepad.exe":[[],[]], "Adobe":[[],[]]} def r_len_d(self): return len(d_licence_numbers) def a_d(self,software,mac): global d_software d_software[software][0].append(mac) return d_software def r_d(self): return d_software def r_l(self): return d_licence_numbers -- http://mail.python.org/mailman/listinfo/python-list
Re: use var to form name of object
gel wrote: > Bruno Desthuilliers wrote: > > > gel wrote: > > > gel wrote: > > > > > > > > >>Hi > > >>I would like to pass a variable in and use it as part of a name of an > > >>object, something like below, where I pass the variable software into > > >>the function and use it as part of the name of the object so that I can > > >>append to it using the other vairables. Any suggestions? > > >> > > >> > > >>def a_d(self,software,mac,time,extra): > > > >>global d_software > > >>d_software.software.append([mac,time,extra]) > > > > > > > > > I sorted it out > > > > > Then do a favour to other persons facing the same problem : share your > > solution. As a side effect, you'll also have your code checked by lot of > > confirmed Python programmer !-) > > > > -- > > bruno desthuilliers > > python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for > > p in '[EMAIL PROTECTED]'.split('@')])" > > OK, I would love to, the reason I did not was for fear of wasting > peoples time with basic stuff... I ended up doing it a bit differently > > what I am doing is using pyro to make a package that can be run on PCs > to control how many PC on a network are running a piece of software,the > function > > def a_d(self,software,mac): > global d_software > d_software[software][0].append(mac) > return d_software > > is in the module on the pyro server. When this object is used on the > client it adds the clients mac address to the dictionary list. When > another client is runs the software being watched it checks how many > are already running by counting the number of mac addresses already in > there. If the number of PCs already running the software is below the > number allowed, which is set in the pyro module it is allowed to > continue to run it. If the limit has been reached the client software > kills the software, Below is the client and the pyro module... > > Client > > import wmi > import time > import Pyro.core > c = wmi.WMI() > o=Pyro.core.getAttrProxyForURI('PYRONAME://:Default.test') > for interface in c.Win32_NetworkAdapterConfiguration (IPEnabled=1): > # print interface.Description, interface.MACAddress > for ip_address in interface.IPAddress: > mac = interface.MACAddress > mac = 1 > current_time = time.time() > sw = "notepad.exe" > > #o.a_d(sw, mac, current_time, "Maybe More Extra Stuff too") > > while 1: > time.sleep(1.0) > ps_li=[] > for process in c.Win32_Process (): > #print process.ProcessId, process.Name > ps_li += [process.Name] > > if sw in ps_li: > if len(o.r_d()[sw][0]) != 0: > if mac in o.r_d()[sw][0]: > print "Already in there" > else: > #ps_id = ps_li.index(sw) > if len(o.r_d()[sw][0]) < o.r_l()[sw]: > o.a_d(sw, mac) > print "There are some" > print o.r_d() > > else: > print "There are none" > for process in c.Win32_Process (): > if process.Name == "notepad.exe": > print process.ProcessId, process.Name > result = process.Terminate () > print process.Name +" has been killed" > else: > o.a_d(sw, mac) > print "First in" > else: > print sw + " not running" > > pyro module > > class testclass: > import wmi > import time > global d_software > global l_notepad > global d_licence_numbers > d_licence_numbers = {"notepad.exe":1, "Adobe":1} > l_notepad =[] > d_software = {"notepad.exe":[[],[]], "Adobe":[[],[]]} > > > def r_len_d(self): > return len(d_licence_numbers) > > def a_d(self,software,mac): > global d_software > d_software[software][0].append(mac) > return d_software > > def r_d(self): > return d_software > > def r_l(self): > return d_licence_numbers To make the client side a little less CPU intensive, I would like to catch the events when a new process starts and when a process ends, using wmi. That will mean that I dont have to search through all running processes. Can anyone help with the best way to trap the starting of a new process and the ending of an existing one? -- http://mail.python.org/mailman/listinfo/python-list
Re: use var to form name of object
Simon Forman wrote: > gel wrote: > > > > > class testclass: > > import wmi > > import time > > global d_software > > global l_notepad > > global d_licence_numbers > > d_licence_numbers = {"notepad.exe":1, "Adobe":1} > > l_notepad =[] > > d_software = {"notepad.exe":[[],[]], "Adobe":[[],[]]} > > > > > Wow! For a second there I thought you could make a "global" class > attribute in a way I'd never seen before... > > But it's turns out you can't. > > >>> k = 0 > >>> class foo: > global k > def wow(self, n): > self.k += n > > > >>> foo.k > > Traceback (most recent call last): > File "", line 1, in -toplevel- > foo.k > AttributeError: class foo has no attribute 'k' > >>> f = foo() > >>> f.k > > Traceback (most recent call last): > File "", line 1, in -toplevel- > f.k > AttributeError: foo instance has no attribute 'k' > >>> f.wow(23) > > Traceback (most recent call last): > File "", line 1, in -toplevel- > f.wow(23) > File "", line 4, in wow > self.k += n > AttributeError: foo instance has no attribute 'k' > >>> > > > BTW, that's a weird place to put import statements. > > Peace, > ~Simon Yeah I am still getting my head around things... not exactly sure what you where saying about the globals, but this works global k k = 5 class foo: def wow(self, n): global k k += n return k f=foo() f.wow(55) -- http://mail.python.org/mailman/listinfo/python-list
How to trap the event of a new process starting with wmi
Below is how it is down with vbscript. What is the best way to convert this to python? strComputer = "." Set objWMIService = GetObject("winmgmts:" _ & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") Set colMonitoredProcesses = objWMIService. _ ExecNotificationQuery("select * from __instancecreationevent " _ & " within 1 where TargetInstance isa 'Win32_Process'") i = 0 Do While i = 0 Set objLatestProcess = colMonitoredProcesses.NextEvent Wscript.Echo objLatestProcess.TargetInstance.Name Loop -- http://mail.python.org/mailman/listinfo/python-list
Re: How to trap the event of a new process starting with wmi
gel wrote: > Below is how it is down with vbscript. What is the best way to convert > this to python? > > strComputer = "." > Set objWMIService = GetObject("winmgmts:" _ > & "{impersonationLevel=impersonate}!\\" & strComputer & > "\root\cimv2") > Set colMonitoredProcesses = objWMIService. _ > ExecNotificationQuery("select * from __instancecreationevent " _ > & " within 1 where TargetInstance isa 'Win32_Process'") > i = 0 > > Do While i = 0 > Set objLatestProcess = colMonitoredProcesses.NextEvent > Wscript.Echo objLatestProcess.TargetInstance.Name > Loop A better question might be is there a method or guide for converting from vbs wmi to python wmi? -- http://mail.python.org/mailman/listinfo/python-list
Re: How to trap the event of a new process starting with wmi
placid wrote: > gel wrote: > > gel wrote: > > > > > Below is how it is down with vbscript. What is the best way to convert > > > this to python? > > > > > > strComputer = "." > > > Set objWMIService = GetObject("winmgmts:" _ > > > & "{impersonationLevel=impersonate}!\\" & strComputer & > > > "\root\cimv2") > > > Set colMonitoredProcesses = objWMIService. _ > > > ExecNotificationQuery("select * from __instancecreationevent " _ > > > & " within 1 where TargetInstance isa 'Win32_Process'") > > > i = 0 > > > > > > Do While i = 0 > > > Set objLatestProcess = colMonitoredProcesses.NextEvent > > > Wscript.Echo objLatestProcess.TargetInstance.Name > > > Loop > > > > A better question might be is there a method or guide for converting > > from vbs wmi to python wmi? > > Dont know about converting vbs to python but using Tim Golden's wmi > module to trap the event of a new process starting is easy. > > wmi module can be found at http://timgolden.me.uk/python/wmi.html > > >>> import wmi > >>> c = wmi.WMI() > >>> watcher = c.watch_for ( > >>> notification_type="Creation" > >>> wmi_class="Win32_Process" > >>> delay_secs=2, > >>> Name='calc.exe' > >>> ) > >>> calc_created = watcher () > >>> print calc_created > > and if you want to trap closing down of processes then change > notification_type to "Deletion" > > > -Cheers Great, thanks for that, where did you find details on using it. I am already using it for another part, but could not find information on watching processes start and stop. -- http://mail.python.org/mailman/listinfo/python-list
Re: How to trap the event of a new process starting with wmi
placid wrote: > gel wrote: > > placid wrote: > > > > > gel wrote: > > > > gel wrote: > > > > > > > > > Below is how it is down with vbscript. What is the best way to > > > > > convert > > > > > this to python? > > > > > > > > > > strComputer = "." > > > > > Set objWMIService = GetObject("winmgmts:" _ > > > > > & "{impersonationLevel=impersonate}!\\" & strComputer & > > > > > "\root\cimv2") > > > > > Set colMonitoredProcesses = objWMIService. _ > > > > > ExecNotificationQuery("select * from __instancecreationevent " _ > > > > > & " within 1 where TargetInstance isa 'Win32_Process'") > > > > > i = 0 > > > > > > > > > > Do While i = 0 > > > > > Set objLatestProcess = colMonitoredProcesses.NextEvent > > > > > Wscript.Echo objLatestProcess.TargetInstance.Name > > > > > Loop > > > > > > > > A better question might be is there a method or guide for converting > > > > from vbs wmi to python wmi? > > > > > > Dont know about converting vbs to python but using Tim Golden's wmi > > > module to trap the event of a new process starting is easy. > > > > > > wmi module can be found at http://timgolden.me.uk/python/wmi.html > > > > > > >>> import wmi > > > >>> c = wmi.WMI() > > > >>> watcher = c.watch_for ( > > > >>> notification_type="Creation" > > > >>> wmi_class="Win32_Process" > > > >>> delay_secs=2, > > > >>> Name='calc.exe' > > > >>> ) > > > >>> calc_created = watcher () > > > >>> print calc_created > > > > > > and if you want to trap closing down of processes then change > > > notification_type to "Deletion" > > > > > > > > > -Cheers > > > > Great, thanks for that, where did you find details on using it. I am > > already using it for another part, but could not find information on > > watching processes start and stop. > > >>> c=wmi.WMI() > >>> help(c) > > ive been using the wmi module for 1.5 months and i had some help from > the author of the module (Tim Golden). Do you have any docs that might help me? -- http://mail.python.org/mailman/listinfo/python-list
Re: How to trap the event of a new process starting with wmi
gel wrote: > placid wrote: > > > gel wrote: > > > placid wrote: > > > > > > > gel wrote: > > > > > gel wrote: > > > > > > > > > > > Below is how it is down with vbscript. What is the best way to > > > > > > convert > > > > > > this to python? > > > > > > > > > > > > strComputer = "." > > > > > > Set objWMIService = GetObject("winmgmts:" _ > > > > > > & "{impersonationLevel=impersonate}!\\" & strComputer & > > > > > > "\root\cimv2") > > > > > > Set colMonitoredProcesses = objWMIService. _ > > > > > > ExecNotificationQuery("select * from __instancecreationevent " _ > > > > > > & " within 1 where TargetInstance isa 'Win32_Process'") > > > > > > i = 0 > > > > > > > > > > > > Do While i = 0 > > > > > > Set objLatestProcess = colMonitoredProcesses.NextEvent > > > > > > Wscript.Echo objLatestProcess.TargetInstance.Name > > > > > > Loop > > > > > > > > > > A better question might be is there a method or guide for converting > > > > > from vbs wmi to python wmi? > > > > > > > > Dont know about converting vbs to python but using Tim Golden's wmi > > > > module to trap the event of a new process starting is easy. > > > > > > > > wmi module can be found at http://timgolden.me.uk/python/wmi.html > > > > > > > > >>> import wmi > > > > >>> c = wmi.WMI() > > > > >>> watcher = c.watch_for ( > > > > >>> notification_type="Creation" > > > > >>> wmi_class="Win32_Process" > > > > >>> delay_secs=2, > > > > >>> Name='calc.exe' > > > > >>> ) > > > > >>> calc_created = watcher () > > > > >>> print calc_created > > > > > > > > and if you want to trap closing down of processes then change > > > > notification_type to "Deletion" > > > > > > > > > > > > -Cheers > > > > > > Great, thanks for that, where did you find details on using it. I am > > > already using it for another part, but could not find information on > > > watching processes start and stop. > > > > >>> c=wmi.WMI() > > >>> help(c) > > > > ive been using the wmi module for 1.5 months and i had some help from > > the author of the module (Tim Golden). > > Do you have any docs that might help me? What would be the best way to watch for multiple pieces of software at the same time, eg. watching for the start up of calc.exe notepad.exe. Or even how could I query what the value of the attribute Name is equal to in the object calc_created from the example above? -- http://mail.python.org/mailman/listinfo/python-list