Code Monkey home page Code Monkey logo

Comments (2)

mllg avatar mllg commented on August 25, 2024

I inspect makeClusterFunctionsTorque.R and I cannot understand how you handle the template, it seems you read the template file once template = cfReadBrewTemplate(template, "##"), and then drop it as it is not returned by the function.

You are right, I read the template file once. But the variable will not be garbage collected, because it lives in the environment of the returned functions. Here is a small example to demonstrate this mechanism (called closure):

pow = function(p) {
  force(p)
  function(x) x^p
}
square = pow(2)
square(1:10)
root = pow(0.5)
root(1:10)

ls.str(environment(square))

After parsing the template once during construction with makeClusterFunctionsTorque, the template is stored as string in the environment of the functions:

ee = environment(reg$cluster.functions$submitJob)
ls.str(ee)
ee$template

If passed to cfBrewTemplate the variable template will get automatically resolved to variable previously defined in respective scope/environment.

Regarding the hooks:
Sorry, I was pointing you in the wrong direction in the other issue. To set the hooks, put something like this in your config file:

# vanilla cluster functions implementations without hooks
cluster.functions = makeClusterFunctionsTorque(template = "~/torque.tmpl")

# hooks is initialized as an empty list, thus we can just set one here
cluster.functions$hooks$pre.submit = function(...) Sys.sleep(2)

from batchtools.

sorhawell avatar sorhawell commented on August 25, 2024

I salute you !
I have overlooked the closure part until now.
thx

from batchtools.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.