Hello,
I've got this working print queue monitor and currently it checks the
queues every 1 second. I'm worried that I might miss events if I set
the delay to more than this. Particularly as I would like to perform
functions depending on status codes. When I don't have a delay set, the
CPU usage is huge 70%.
My question is, is there an 'intelligent' way of monitoring the spooler?
I guess what I'm thinking is some low cpu method of watching for
activity on the spooler, and triggering my program as the spooler stops
and starts.
Suggestions?
Regards,
Guy
Here's my code so far:
try:
import win32print
except:
print 'win32all required .'
import time
#constants
wp = win32print
# lists and dictionaries of constants
ptypelist =
[(wp.PRINTER_ENUM_SHARED,'shared'),(wp.PRINTER_ENUM _LOCAL,'local'),(wp.PRINTER_ENUM_CONNECTIONS,'netw ork')]
cmds = {'Pause':wp.JOB_CONTROL_PAUSE, 'cancel':wp.JOB_CONTROL_CANCEL,
'resume':wp.JOB_CONTROL_RESUME,
'prior_low':wp.MIN_PRIORITY,'prior_high':wp.MAX_PR IORITY,'prior_normal':wp.DEF_PRIORITY
}
status codes =
{'deleting':wp.JOB_STATUS_DELETING,'error':wp.JOB_ STATUS_ERROR,'offline':wp.JOB_STATUS_OFFLINE,'pape r
out':wp.JOB_STATUS_PAPEROUT,'paused':wp.JOB_STATUS _PAUSED,'printed':wp.JOB_STATUS_PRINTED,'printing' :wp.JOB_STATUS_PRINTING,'spooling':wp.JOB_STATUS_S POOLING}
class PMFuncs:
def __init__(self):
# initialise the list of printers
self.PList =[]
def PrinterList(self):
# returns a list of dicts.
# this gets the default printer
tmpdic ={}
DefPName = win32print.GetDefaultPrinter()
# Get the default printer firstso we can add this to the list
of printers
for pt in ptypelist:
try:
for (Flags,pDescription,pName,pComment) in
list(win32print.EnumPrinters(pt[0],None,1)):
tmpdic ={}
tmpdic['PType'] = pt[1]
tmpdic['Flags'] = Flags
tmpdic['Description'] = pDescription
#test for if this is the default printer
if pName == DefPName:
tmpdic['DefPrinter':True]
else:
tmpdic['DefPrinter':False]
tmpdic['Name'] = pName
tmpdic['Comment'] = pComment
self.PList.append(tmpdic)
except:
pass #no printers of this type so don't add anything
return self.PList #list of installed printers
def GetJobList(self,printer):
phandle = win32print.OpenPrinter(printer)
#now get all the print jobs (start at job 0 and -1 for all jobs)
jlist = win32print.EnumJobs(phandle,0,-1,1)
win32print.ClosePrinter(phandle)
return jlist # this lists all jobs on all printers
def GetJobInfo(self,printer,jobID):
phandle = win32print.OpenPrinter(printer)
ilist = win32print.GetJob(phandle,jobID,1)
win32print.ClosePrinter(phandle)
return ilist #this lists all info available at level 1 for
selected job.
def SetJobCmd(self, printer, jobID , JobInfo , RCmd ):
phandle = win32print.OpenPrinter(printer)
win32print.SetJob(phandle,jobID,1,JobInfo,Cmds[RCmd])
win32print.ClosePrinter(phandle)
# test functions
e = PMFuncs()
while 1:
time.sleep(1)
e = PMFuncs()
for i in e.PrinterList():
try:
p = e.GetJobList(i['Name'])
for w in p:
print e.GetJobInfo(i['Name'],w['JobID'])
except:
pass 2 2770
Guy Robinson: I've got this working print queue monitor and currently it checks
the queues every 1 second. I'm worried that I might miss events if I set the delay to more than this. Particularly as I would like to perform functions depending on status codes.
You could pause all the printers, live with the one second delay, and
selectively release jobs for printing and deletion.
Alternately, missing entire jobs seems to indicate that everything is
working as it should. Aren't the most interesting status' the 'things
aren't normal' ones?
When I last needed to monitor printers, I monitored the spool queue on
disk instead, but I was interested in capturing the spooled content
and not the status.
HTH,
--
Emile van Sebille em***@fenx.com
Emile van Sebille wrote: Guy Robinson:
I've got this working print queue monitor and currently it checks
the
queues every 1 second. I'm worried that I might miss events if I set the delay to more than this. Particularly as I would like to perform functions depending on status codes.
You could pause all the printers, live with the one second delay, and selectively release jobs for printing and deletion.
Or maybe arrange for all jobs to be placed in the queue in a "paused"
state, and have your monitor release the jobs?
Either way, for the OP, the general solution to this kind of question is
to find the best solution in *any* language. Most often, you will find
sample code in either VB or C++ - often from MS - but it can generally
be ported to Python fairly easily once you understand exactly what you
are trying to do.
Mark. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Martin Hampl |
last post by:
Hi,
I am using PostgreSQL 7.4, but I did have the same problem with the
last version.
I indexed the column word (defined as varchar(64)) using lower(word).
If I use the following query,...
|
by: Tom |
last post by:
I have a small window that I want positioned at the lower right of an open
MDI window. I know how to size it and place it (via .Left and .Top during
the form load event) but what I can't figure out...
|
by: Eric Lindsay |
last post by:
Should HTML 4.01 Strict markup be done in upper case or in lower case?
I understand that HTML allows either upper or lower case. I also notice
that XHTML apparently requires lower case. However I...
|
by: lordhunter9r9za |
last post by:
No One runs the world. ... Are you on track yet?
About me:
Warm, skilled, caring, friend of wild life . Charming...
Yeah, and the hotest hotties think I'm sexy, sweet, and warm....
|
by: Tim Golden |
last post by:
José Roberto wrote:
Does this help?
http://timgolden.me.uk/python/win32_how_do_i/print.html#rough_and_ready
TJG
|
by: BA |
last post by:
Hi Everyone,
I have an application that sits behind a server farm, the application needs
to pass its NLB IP address in the message that it sends to another service.
From C# code, how can I...
|
by: john20 |
last post by:
Hi All,
I am having a problem with accesing function in the page. i have a page say user.aspx in the page load method
i am calling function to validate the user.
it works fine when single...
|
by: Alexey Moskvin |
last post by:
Hi!
I have a set of strings (all letters are capitalized) at utf-8,
russian language. I need to lower it, but
my_string.lower(). Doesn't work.
See sample script:
# -*- coding: utf-8 -*-
s1 =...
|
by: Thekid |
last post by:
I had made a post about making a loop using letters instead of numbers and dshimer gave me this solution:
for i in range(65,70):
for j in range(65,70):
for k in range(65,70):
...
|
by: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
| |