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 ..

  1. why rails doing magic?

  2. 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

Popular posts from this blog

iis - ASP.Net Core CreatedAtAction in HttpPost action returns 201 but entire request ends with 500 -

Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12:test (default-test) on project.Error occurred in starting fork -