deephaven / deephaven-core

Deephaven Community Core
Other
249 stars 79 forks source link

Implicit Python Application Mode Pattern #1134

Open nbauernfeind opened 3 years ago

nbauernfeind commented 3 years ago

Devin and I believe that we can offer an alternative python application mode experience that would work as follows:

from deephaven import TableTools
from deephaven import Application

def demo_implicit():
  print("Running Implicit Demo.")
  size_imp = 42
  hello_imp = TableTools.emptyTable(size)
  world_imp = TableTools.timeTable("00:00:01")

Application.initialize_implicitly(demo_implicit)

Here hello_imp and world_imp would both be exported as Fields, but none of the variables would leak to the QueryScope.

Note that this is in contrast to the other "pretty" python application mode approach:

from deephaven import TableTools
from deephaven import Application, ApplicationState

def demo_app(app: ApplicationState):
  print("Running Strict App Demo.")
  size = 42
  app.setField("hello", TableTools.emptyTable(size))
  app.setField("world", TableTools.timeTable("00:00:01"))

Application.initialize(demo_app)
devinrsmith commented 3 years ago

We've got a version of initialize_implicitly that works when the invoked function uses global.