Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7851513
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T19:12:10+00:00 2026-06-02T19:12:10+00:00

I’m working on trying to get a print server running using this: http://newcenturycomputers.net/projects/rawprintserver.html I’ve

  • 0

I’m working on trying to get a print server running using this: http://newcenturycomputers.net/projects/rawprintserver.html

I’ve modified spooler.py to write to a file and everything is working OK save for one issue: the job seems to take a long time considering what is being printed…

The job gets received and it chugs along for a solid minute before actually finishing. This seems like an excessively long time for a 1kb txt file with the word ‘test’ in it…

It exhibits the same behavior whether using Windows or Mac, so it’s not an OS thing…

This is the modified def in spooler.py

class printer(base_printer):
    def sendjob(self, fp, title = None):
        # title is irrelevant here
        print "Begin sendjob def..."
        out = open('/tmp/printserv/outs/' + str(time.time()).split('.')[0]+".txt", 'w')
        blk = fp.read(8192)
        while blk:
            out.write(blk)
            print "Block written..."
            blk = fp.read(8192)
            print "while loop done..."
        rc = out.close()
        if rc is not None:
            print "Error: lpr returns %02x" % rc
        else:
            print "OK DONE"

This is the main print handler class (from printserver.py) that handles the job:

class print_handler(asyncore.dispatcher):

    def __init__(self, conn, addr, server, jobnumber):
        asyncore.dispatcher.__init__(self, sock = conn)
        self.addr = addr
        self.server = server
        self.jobname = JOBNAME % jobnumber
        self.fp = open(self.jobname, "wb")
        print "Receiving Job from %s for Printer <%s> (Spool File %s)" \
            % (addr, self.server.printer.printer_name, self.jobname)

    def handle_read(self):
        data = self.recv(8192)
        print "Starting handle_read"
        if self.fp:
            print "begin self.fp.write..."
            self.fp.write(data)
            print "end self.fp.write.."

    def writable(self):
        print "Writable return 0"
        return 0

    def handle_write(self):
        print "handle_write pass"
        pass

    def handle_close(self):
        print "Printer <%s>: Printing Job %s" \
            % (self.server.printer.printer_name, self.jobname)
        if self.fp:
            self.fp.close()
            self.fp = None
        fp = open(self.jobname, "rb")
        self.server.printer.sendjob(fp)
        fp.close()
        try:
            os.remove(self.jobname)
        except:
            print "Can't Remove <%s>" % self.jobname
        self.close()

and the mainloop def (also in printserver.py):

def mainloop(config):

    if config["spooldir"]:
        os.chdir(config["spooldir"])

    for i in range(len(config["printer"])):
        args = string.split(config["printer"][i], ",", maxsplit = 1)
        prn = args[1].strip()
        port = int(args[0].strip())
        p = print_server('',
            port, spooler.printer(prn))
        servers.append(p)

    try:
        try:
            asyncore.loop(timeout = 1.0)
        except KeyboardInterrupt:
            pass
    finally:
        print "Print Server Exit"

those print‘s get logged in a logfile which looks like this:

[2012/04/26 10:39:58] Raw Print Server Startup: PID = 15695
[2012/04/26 10:39:58] Starting Printer <lpr> on port 515
[2012/04/26 10:40:01] Receiving Job from ('1.2.3.4', 55070) for Printer <lpr> (Spool File RawPrintJob00001.prn)
[2012/04/26 10:40:01] Writable return 0
[2012/04/26 10:40:01] Starting handle_read
[2012/04/26 10:40:01] begin self.fp.write...
[2012/04/26 10:40:01] end self.fp.write..
[2012/04/26 10:40:01] Writable return 0
[2012/04/26 10:40:02] Writable return 0
[2012/04/26 10:40:03] Writable return 0
[2012/04/26 10:40:04] Writable return 0
                 [[SNIP]]
[2012/04/26 10:41:39] Writable return 0
[2012/04/26 10:41:40] Writable return 0
[2012/04/26 10:41:41] Writable return 0
[2012/04/26 10:41:42] Starting handle_read
[2012/04/26 10:41:42] begin self.fp.write...
[2012/04/26 10:41:42] end self.fp.write..
[2012/04/26 10:41:42] Writable return 0
[2012/04/26 10:41:42] Printer <lpr>: Printing Job RawPrintJob00001.prn
[2012/04/26 10:41:42] Begin sendjob def...
[2012/04/26 10:41:42] Block written...
[2012/04/26 10:41:42] done writing blocks...
[2012/04/26 10:41:42] OK DONE
[2012/04/26 10:41:42] Starting handle_read

at this point, the job is finished and the file has been written. Nothing else gets logged until the next job comes in. As you can see, this took over 1.5 minutes to complete.

My question is: how could it possibly take almost 2 minutes to handle a 1k file? This is all local on gigabit LAN so it must be something with the way the code is handling the job… One thing I have noticed is that the printed jobs seem to have a lot of trailing whitespace. Could it be that it is looking for an EOF or something and eventually just timing out?

Any pointers appreciated

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T19:12:11+00:00Added an answer on June 2, 2026 at 7:12 pm

    This turned out be an issue with how the printer was configured on the client. It was set to lpr instead of to RAW.

    Coincidentally, I came across a perl script that will do the same thing as the py script (kinda). With the perl script, there is much less code to achieve the same goal (that goal for me being to simply catch a stream and write to a file; rps is more verbose than I need).

    Here:

    #!/usr/bin/perl 
    use IO::Socket::INET;
    use POSIX qw(strftime);
    $print_time = strftime "%Y%m%d-%H_%M_%S", localtime; 
    $myport=515; 
    $pserve=IO::Socket::INET->new(LocalPort => $myport,Type=>SOCK_STREAM,Reuse=>1,Listen=>1) or die "Socket error: $!\n"; 
    while ($pjob=$pserve->accept()) {
        open(J,">>/tmp/printserv/outs/".$print_time.".txt") or print "File open error: $!\n"; 
        while (<$pjob>) { 
            print J "$_"; 
        } 
        close J; 
        close $pjob;
        print  "DONE..."; 
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have this code to decode numeric html entities to the UTF8 equivalent character.
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I have thousands of HTML files to process using Groovy/Java and I need to
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
That's pretty much it. I'm using Nokogiri to scrape a web page what has
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to understand how to use SyndicationItem to display feed which is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.