8000 is it posible launch another pool inside a thread? · Issue #60 · torch/threads · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

is it posible launch another pool inside a thread? #60

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ou 965A r terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
CriztianiX opened this issue Apr 26, 2016 · 0 comments
Open

is it posible launch another pool inside a thread? #60

CriztianiX opened this issue Apr 26, 2016 · 0 comments

Comments

@CriztianiX
Copy link

See this piece of code:

local threads = require 'threads'
local parser = require("parser")["discounts"]
local config = require("lapis.config").get()

-- Returns paginator instance
local paginator = function()
    local model = require("models")["discounts"]
    return model:paginated(model:query())
end
-- Returns elasticsearch client
local elasticsearch = function()
    local elasticsearch = require "elasticsearch"
    return elasticsearch.client{
      hosts = config.elasticsearch.hosts
  }
end

local nthread = config.nthread
local pages = paginator():num_pages()
local pool = threads.Threads(
   nthread,
   function(threadid)
      paginated = paginator()
      client = elasticsearch()
      from_json = require("lapis.util").from_json
      es_type = paginated.model:table_name()
      print('starting a new thread/state number ' .. threadid)
   end
)

local jobdone = 0
for i=1,pages do
   pool:addjob(function()
       local items = paginated:get_page(i)
     for i=1,#items do
       local data, err = client:index({
          index = config.elasticsearch.index,
                type = es_type,
          id = items[i].id,
          body = parser(items[i])
         })
     end
    return __threadid
   end,
   function(id)
      jobdone = jobdone + 1
   end)
end

pool:synchronize()
print(string.format('%d jobs done', jobdone))
pool:terminate()

So, can i create another pool inside pool:addjob() ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant
0