Project

General

Profile

Actions

Bug #17801

closed

repeated read from PTY blocks all Fibers

Added by pebauer (peter bauer) 5 months ago. Updated 3 months ago.

Status:
Closed
Priority:
Normal
Target version:
-
ruby -v:
ruby 3.0.1p64 (2021-04-05 revision 0fb782ee38) [x86_64-linux]
[ruby-core:103439]

Description

Ruby version:
ruby 3.0.1p64 (2021-04-05 revision 0fb782ee38) [x86_64-linux]

used Scheduler:
https://github.com/ruby/ruby/blob/master/test/fiber/scheduler.rb

Example Code which should work:

require 'pty'
require "./scheduler.rb"

line_event = TracePoint.new(:line) do |t|
  p [t.lineno, t.method_id, t.path]
end

Fiber.set_scheduler(Scheduler.new)

master, slave = PTY.open
read, write = IO.pipe
pid = spawn("bash", :in=>read, :out=>slave)
read.close     # we dont need the read
slave.close    # or the slave

line_event.enable do

Fiber.schedule do
  loop do
    puts "date"
    write.puts "date"
    sleep 1
  end
end

Fiber.schedule do
  loop do
    puts master.gets.chomp
    puts master.gets.chomp # this line blocks all fibers, why ?
    puts "test"
    sleep 1
  end
end

#write.close 
end
Actions

Also available in: Atom PDF