How to run TabPy as Windows Service

People ask this question in different ways:

  • How do I make TabPy to start automatically?
  • How can I run TabPy in background?
  • How can I run TabPy as if it was a service?

Answer to these questions are different depending on your OS and can even be different for different versions of the same OS.

In this post I am showing the simplest way to make TabPy something like a Windows service – which means it starts automatically and runs in background. For the following steps, I assume you have TabPy environment configured in Anaconda (read https://tabscifi.golovatyi.info/category/anaconda/ for more examples and how-to’s for using Anaconda with analytics extensions).

With my Anaconda I have tabpy_demo environment where TabPy package is installed:

Next, I created c:\demo\TabPy_as_a_service folder with the simple config file in it:

[TabPy]
TABPY_PORT = 9004
[loggers]
keys=root
[handlers]
keys=rootHandler
[formatters]
keys=rootFormatter
[logger_root]
level=DEBUG
handlers=rootHandler
qualname=root
propagete=0
[handler_rootHandler]
class=handlers.RotatingFileHandler
level=DEBUG
formatter=rootFormatter
args=('tabpy_log.log', 'a', 1000000, 5)
[formatter_rootFormatter]
format=%(asctime)s %(levelname)ss:%(lineno)d): %(message)s
datefmt=%Y-%m-%d,%H:%M:%S

For more information about custom TabPy config consider reading posts at https://tabscifi.golovatyi.info/category/tabpy-configuration/.

Now let’s create a task with Task Scheduler (Start->Task Scheduler). In Task Scheduler Library click Create Task… on Actions pane on the right. In the task dialog specify the task name (I use “TabPy as a Service” in this example), and choose if you want the task to run with specific account.

On Triggers tab click New… and specify At startup – now the task runs automatically at system startup.

On Actions tab add new action Start a program and use the following parameters:

  • For Program/script use %windir%\System32\cmd.exe.
  • For arguments at Add arguments enter `”/K c:\ProgramData\Anaconda3\Scripts\activate.bat tabpy_demo && tabpy –config tabpy.conf”`. More about the string below.
  • For Start in specify folder you have your config file in. The same folder will have TabPy logs in my case.

The arguments string above means:

  • /K tells cmd to run the command and continue (documentation for cmd is here – https://docs.microsoft.com/en-us/windows-server/administration/windows-commands/cmd).
  • c:\ProgramData\Anaconda3\Scripts\activate.bat tabpy_demo activates Anaconda environment tabpy_demo. For you this part will be different: Anaconda can be installed in a different folder and TabPy environment will have a different name.
  • tabpy --config tabpy.conf starts TabPy with the custom configuration file in c:\demo\TabPy_as_a_service folder specifies as Start in folder.

On Conditions and Settings tabs change parameters as needed.

Now you can test the task – click Run action on Actions pane. If the task was configured properly you’ll see TabPy is running.

Log files for TabPy can be found in the same c:\demo\TabPy_as_a_service folder where config file is:

Now we have TabPy scheduled to start on a system start up.

One question remains – how can I make cmd window go away? It is possible and requires a little bit of scripting so I am saving it for the next post 😉

Why calculations for my Python/R/… SCRIPT_x field are per row?

Question Advanced Analytics Team hears somewhat regular is exactly what the title for the post says:

I created a calculated field and see the calls for TabPy/Rserve/MatLab/Einstein/etc. are made for each row. Why is that and what can I do for the field to be calculated once for the whole column?

Short answer is that behavior is how table calculation is computed – Tableau is evaluating each different value due to the settings. To change the behavior set the dimension as Specific Dimensions:

With Specific Dimensions data will be sent for calculation in one call.

For technical details read Tableau documentation on how to transform values with table calculations – https://help.tableau.com/current/pro/desktop/en-us/calculations_tablecalculations.htm#specific-dimensions.

Also consider watching these video recordings from Tableau Conference which provide some deeper dive into the topic and beyond:

  • Data science applications with TabPy/R:
  • Even More Data Science Applications in Tableau: