From: "Zachary P. Landau" Date: 2004-08-29T07:28:59+09:00 Subject: Blocking Problem --+QahgC5+KEYLbs62 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Hello, I'm having trouble with IO blocking when reading from a device. It may be hard for people to help since most people won't be able to test this themselves, but I'll give it a shot. I'm trying to read from the CueCat Linux driver, which sits in /dev/scanner/cuecat. It is sort of like a pipe, you can use File.read and it outputs a line with a barcode (and some other information). The problem is, I can't avoid blocking. There is a GTK application, and then a separate thread that tries to read barcodes and whenever it finds one, it tells the GTK app. So my code looks like this: Thread.new do File.open(CUECAT_DEV, File::RDONLY | File::NONBLOCK) do |cuecat| loop do id, barcode_type, barcode = cuecat.gets.split(/,/) # do stuff with the barcode end end end When I use a named pipe instead of CUECAT_DEV, it doesn't block. But when I use the actual /dev/scanner/cuecat, it blocks. Unfortunately, blocking locks up the entire application. I tried getting around the issue by using Gtk.timeout_add instead, but that didn't help. The mailing list has some posts about blocking problems, but they are related to sockets and pipes. As I mentioned earlier, the above code works when CUECAT_DEV is a pipe. -- Zachary P. Landau GPG: gpg --recv-key 0x24E5AD99 | http://kapheine.hypa.net/kapheine.asc --+QahgC5+KEYLbs62 Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.5 (GNU/Linux) iD8DBQFBMQcfCwWyMCTlrZkRAutAAJ9Mqvz/L6eknUCAHzgqG09EqZBbJwCfR81Y CPQJPCFqkc8T80asv3AJ2IU= =6cbY -----END PGP SIGNATURE----- --+QahgC5+KEYLbs62--