ruby on rails - Why does Time.zone get set to nil inside Thread -
here mean ...
require 'rubygems' gem 'activesupport','4.2.6' require 'active_support/all' time.zone = 'est' puts "print current time zone -- [#{time.zone}]" thread.new puts "time zone(will nil) instead thread -- [#{time.zone}]" end sleep 1
o/p
print current time zone -- ((gmt-05:00) est) time zone(will nil) instead thread -- ()
clearly rails doing magic on here time.zone inside thread.
so question ..
why rails doing magic?
where in rails code that.(a link code great)
if have @ time.zone
can see set current thread, seems intended behaviour.
you can either store in variable , call way or set time.zone 'est' every time in create thread , call time.zone subsequently.
here's example of what's happening
thread.current[:foo] = 'bar' thread.current[:foo] #=> "bar" thread.new { p thread.current[:foo] } #=> nil
i'm not able answer why rails magic many of things does, believe may every thread can operate on different time zone.
Comments
Post a Comment