473,396 Members | 1,915 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Timeout on file write?

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...
Jul 18 '05 #1
4 4507
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" <nb*****@visi.com> wrote in message
news:40***********************@newsreader.visi.com ...
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...

Jul 18 '05 #2
Larry Bates <lb****@swamisoft.com> 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...

Jul 18 '05 #3
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
Jul 18 '05 #4
Mathias Waack <M.*****@gmx.de> 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!
Jul 18 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: David Berry | last post by:
Hi All. I have a SQL Statement on an ASP page that only returns 4 records. When I run it in SQL Server or Query Analyzer it runs in less than a second. When I run it from my ASP page I get: ...
12
by: Edward Rothwell | last post by:
I have a web site where once a user has logged on I store their MemberID in a global variable in the global.asa file. Then in other pages I find out which member I am dealing with by looking at...
4
by: Scott Baxter | last post by:
Hello, I got the following scripts to upload files to my directories I call insert.htm Browse for a file, then click 'submit' It works for small files, and for a small .mdb (access file)
1
by: Joey Chömpff | last post by:
Hello, When I'm uploading an file to a JRun WebServer (third party) with a Windows Forms application, l always get an TimeOut while uploading, all other request who doesn't request an post are...
2
by: Greg Decos | last post by:
I am using forms authentication using a FormsAuthenticationTickets set to expire in 30 minutes and the ticket is added to the collection of cookies. I am not sure where the following values are...
2
by: Chris Langston | last post by:
I have a Web Server running IIS 5 or 6 on Windows 2K and Windows 2003 Server that is experiencing strange shutdown problems. We are using ASP.NET v1.1 and our application is written in VB.NET ...
2
by: Lisa Pearlson | last post by:
Hi, I am wanting to write an internet 'server' program. For ease, I want to use PHP-CLI with XINET super server. XINET communicates with the 'server' program via STDIN/STDOUT. I'm not sure...
0
by: Stefan Schwarzer | last post by:
Hi all! For my FTP library module ftputil , some users have asked for a way to avoid server timeouts (FTP status code 421). But I haven't found out yet how I can do this in all cases. I try...
1
by: a.r.austin | last post by:
Hello, I am trying to download a few files one after another from a remote server. Problem is that I don't know how to, or if I am able at all, set a time out for download. I don't want to time...
4
by: rowan | last post by:
I'm writing a driver in Python for an old fashioned piece of serial equipment. Currently I'm using the USPP serial module. From what I can see all the serial modules seem to set the timeout when...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.