Yep, I've taken the native threads path. Got the thread running, got even an http server running in that thread. But now, GIL is killing me. Can't call ruby from that second native thread...
Latest posts made by SR20VET
-
RE: Ruby 2.0.0 Threads in SU | how to keep a subthread running?
-
RE: Ruby 2.0.0 Threads in SU | how to keep a subthread running?
To make sure the subthread is running, we have to put the main thread in a sleep state.
This is because Ruby does switch to another thread (if existing) when a thread goes into a sleep state.Now, is there a way to automatically put the main thread in a sleep state when the user is not interacting with SU? Once the user starts to interact (mouse movement, click, ...) the sleep state should be interrupted.
I'm not aware of such an event in SU.
For now this:
message_pump = UI.start_timer(0.1, true) do sleep(0.1) end
does help a bit, but ofcourse, this drastically affects SU performance. Even sleeping for 0.01 seconds does..
-
RE: Ruby 2.0.0 Threads in SU | how to keep a subthread running?
Ok tt_su, I might have to go the hard way then, and use native threads in a c++ extension.
-
RE: Ruby 2.0.0 Threads in SU | how to keep a subthread running?
I have the same issues with your latest code. When I simply enter the code, press ENTER, wait a couble of seconds and then type seconds, still not a proper amount of seconds.
Although it seems that, while I'm writing this post, the thread is running... while at the start of the thread I entered "seconds" a couple of times, still with about 10 seconds.
I'll try: seconds = 0; t = Thread.new(){ while true; seconds += 1; sleep(1) end }; t.run
and puts "seconds: #{seconds} and time: #{Time.now}"; a few times. Here is the result in the console, it does run, but not perfect:seconds = 0; t = Thread.new(){ while true; seconds += 1; sleep(1) end }; t.run
#<Thread:0x92a18d8 run>
puts "seconds: #{seconds} and time: #{Time.now}";
seconds: 1 and time: 2014-08-14 23:39:00 +0200
nil
puts "seconds: #{seconds} and time: #{Time.now}";
seconds: 7 and time: 2014-08-14 23:39:07 +0200
nil
puts "seconds: #{seconds} and time: #{Time.now}";
seconds: 14 and time: 2014-08-14 23:39:15 +0200
nil
puts "seconds: #{seconds} and time: #{Time.now}";
seconds: 25 and time: 2014-08-14 23:39:28 +0200
nil
puts "seconds: #{seconds} and time: #{Time.now}";
seconds: 34 and time: 2014-08-14 23:39:39 +0200
nil
puts "seconds: #{seconds} and time: #{Time.now}";
seconds: 43 and time: 2014-08-14 23:39:50 +0200
nil -
RE: Ruby 2.0.0 Threads in SU | how to keep a subthread running?
That's funny. If I close the console it does count indeed! But, when I press ENTER after entering the script, sit and wait for 15 seconds and then enter seconds, it does return 1 - 2
It look like the SU window has to have focus or a mouse hover.
-
Ruby 2.0.0 Threads in SU | how to keep a subthread running?
Hi SU,
I'm testing some multithreading in Ruby.
It seems like the main thread goes into a sleep state when the user is not interacting with Sketchup and/or no script is executing.Take a look at this:
seconds = 0; counter_thread = Thread.start do loop do seconds += 1; sleep(1); end#do end#do
If I just leave the ruby console for what it is after entering this script and don't interact with SU for some seconds, this new thread doesn't run. If I type
seconds
in the console it just says, 1 or 2. However, if I do react with SU, just move the mouse, change the camera position, ... the thread does run and the seconds gets updated.
Spawning a timer on the main thread also keeps the message pump running, but not at full "speed". After some time the seconds are incorrect.
I was wondering if there is some way to keep a subthread running, without the need to interact with SU?
-
RE: Post-its in SketchUp screen (DCExamples.skp)
draw2d and Chunky_png could accomplish the same result with some dynamic options.
-
RE: Rbs weird behaviour on modules
Ok, thanks for the workaround. You should expect that no mather you use rb's or rbs's, they behave the same way...
-
Rbs weird behaviour on modules
Today I ran into this weird behaviour when scrambling my scripts into an rbs.
Lets say I have the folowing script:
module MyModule1 def self.load_second_script Sketchup;;require 'second_script' end#def end#module
in seconds_script.rb(s) i have:
module MyModule1 module MyModule2 end#module end#module
next, I do:
MyModule1.load_second_script
While testing with rb, this eventually gives
MyModule1;;MyModule2
as a valid module.
With rbs this results inMyModule1;;MyModule1;;MyModule2
Has anyone noticed this before?
Regards