Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Python WMI Event Handler - Consumer

Reply
Thread Tools

Python WMI Event Handler - Consumer

 
 
Dips
Guest
Posts: n/a
 
      08-05-2003
Python Gurus,

Is it possible to write python WMI event consumer using event handler
rather than polling WMI?


I got the equivalent C# code snippet from
http://www.ondotnet.com/pub/a/dotnet...04/07/wmi.html

using System;
using System.Management;
using System.Collections;

class WSMonitor
{
bool pleaseContinue = true;

public void doit()
{
try
{

int processId =
System.Diagnostics.Process.GetCurrentProcess().Id;
int workingSet = 30000000;
string wqlQuery = String.Format(
@"SELECT * FROM __InstanceModificationEvent WITHIN 1
WHERE TargetInstance ISA 'Win32_Process' AND
TargetInstance.ProcessId = {0} AND
TargetInstance.WorkingSetSize >= {1} AND
PreviousInstance.WorkingSetSize < {2} ",
processId, workingSet, workingSet);

WqlEventQuery query = new WqlEventQuery(wqlQuery);
ManagementEventWatcher watcher =
new ManagementEventWatcher(query);
watcher.EventArrived +=
new EventArrivedEventHandler(onEvent);

watcher.Start();
ArrayList array = new ArrayList();
for (int i = 0; pleaseContinue; ++i)
{
array.Add(1);

if (i % 1000 == 0)
System.Threading.Thread.Sleep(1);
}

watcher.Stop();
}
catch (ManagementException e)
{
Console.WriteLine("Management exception: " + e);
}
}

public void onEvent(object sender, EventArrivedEventArgs e)
{
pleaseContinue = false;
Console.WriteLine("You're a big boy now!");
}
}

Thanks
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Event Handler that creates adds another event handler kaczmar2@gmail.com ASP .Net 1 02-22-2007 07:37 AM
problem in changing the actual event handler into our own event ashok.dhananjeyan@gmail.com Javascript 0 10-30-2006 02:32 PM
rendering Button inside Render() event, makes it loose its click event handler association sonic ASP .Net 1 01-07-2005 06:33 PM
How to recall add event from an Event handler?? RC ASP .Net Web Controls 1 01-06-2005 07:44 PM
Passing event from dynamically created element and event handler? Adi Javascript 2 02-23-2004 02:44 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57