Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Timeout on file write?

Reply
Thread Tools

Timeout on file write?

 
 
Chris Farley
Guest
Posts: n/a
 
      06-26-2004
I'm working on a cross-platform Python program that prints to a receipt
printer. The code is simple, I just do something like this:

printer = file('/dev/lp0','w') # on Win32, change to 'lpt1'
p.write("whatever")
p.close()


I would like to gracefully handle situations such as when the paper is out
or the printer is powered off. Right now the program just hangs.

Suggestions? Thanks...
 
Reply With Quote
 
 
 
 
Larry Bates
Guest
Posts: n/a
 
      06-26-2004
Not tested, but you might want to take a look at:

http://www.geocities.com/dinceraydin.../indexeng.html

second option, you could try something like:
p.write("whatever")
try:
p.write("whatever")
p.flush()

except:
print "Write error on receipt printer"

p.close()

Just possible solutions, not tested.

HTH,
Larry Bates
Syscon, Inc.

"Chris Farley" <(E-Mail Removed)> wrote in message
news:40dda426$0$32608$(E-Mail Removed) ...
> I'm working on a cross-platform Python program that prints to a receipt
> printer. The code is simple, I just do something like this:
>
> printer = file('/dev/lp0','w') # on Win32, change to 'lpt1'
> p.write("whatever")
> p.close()
>
>
> I would like to gracefully handle situations such as when the paper is out
> or the printer is powered off. Right now the program just hangs.
>
> Suggestions? Thanks...



 
Reply With Quote
 
 
 
 
Chris Farley
Guest
Posts: n/a
 
      06-26-2004
Larry Bates <(E-Mail Removed)> wrote:

> second option, you could try something like:
> p.write("whatever")
> try:
> p.write("whatever")
> p.flush()


> except:
> print "Write error on receipt printer"


> p.close()


This doesn't work, as the call to flush just hangs if the printer is
powered down. It does not throw an exception.

Would it work to start a new thread, and if the thread doesn't return
in a specified time, destroy it? I've read that Python thread's can not
be interrupted, so I'm a bit skeptical that this would work...

 
Reply With Quote
 
Mathias Waack
Guest
Posts: n/a
 
      06-27-2004
Chris Farley wrote:

> I would like to gracefully handle situations such as when the paper
> is out or the printer is powered off. Right now the program just
> hangs.


The simplest way would be to use a timeout as described in the python
lib docs, have a look at the signal module.

Mathias
 
Reply With Quote
 
Chris Farley
Guest
Posts: n/a
 
      06-30-2004
Mathias Waack <(E-Mail Removed)> wrote:

> The simplest way would be to use a timeout as described in the python
> lib docs, have a look at the signal module.


Thank you, that's exactly what I needed!
 
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
Timeout::timeout and Socket timeout Mark Probert Ruby 1 10-06-2004 09:30 AM
Timeout expired. The timeout period elapsed prior to obtaining a connection from the pool. This may have occurred because all pooled connections were in use and max pool size was reached. Guoqi Zheng ASP .Net 4 06-03-2004 06:39 PM
Session contents lost despite Session.Timeout = 3000; and <sessionState mode="InProc" cookieless="false" timeout="300"> Carpe Diem ASP .Net 3 02-23-2004 07:10 PM
web.config session timeout and forms authentication timeout Do ASP .Net 2 11-23-2003 02:27 PM
Re: Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding. Bob Johnson ASP .Net 0 08-07-2003 12:52 PM



Advertisments