It would be helpful if you stated what you expected the results to be versus what you are seeing. Given the code you provided, people could assume what you expected for results, but it is just so much easier to explicitly state it. That said, assuming has never stopped me....
I assume what is confusing to you is that you can continue to create the same table over and over in_memory and that it never generates an error. Using a similar but slightly different example, it is illustrative to compare using in_memory in the interactive Python window (which is what I assume you are doing) and using in_memory in the accompanying, standalone Python interpreter.
Interactive Python window:
arcpy.CreateTable_management('in_memory', 'tmpTable')
<Result 'C:\\Users\\jbixby\\Documents\\ArcGIS\\Projects\\MyProject\\MyProject.gdb\\tmpTable0'>
arcpy.Exists('in_memory/tmpTable')
False
Standalone Python interpreter:
>>> import arcpy
>>> arcpy.CreateTable_management('in_memory', 'tmpTable')
<Result 'in_memory\\tmpTable'>
>>> arcpy.Exists('in_memory/tmpTable')
True
I am guessing, or should I say assuming, you and most others would expect the results from the standalone Python interpreter.
Before getting to my main point, there are a couple of minor points to cover in the code examples above. First, one can see that using in_memory in the interactive Python window is actually creating the table on-disk, not in-memory. Given that in_memory means on-disk and not in-memory in the interactive Python window, it is possible to create the same table over and over because each call using in_memory isn't actually referencing the same place, well, the same object.
Now the logical question is why in_memory doesn't actually mean in-memory with the interactive Python window in ArcGIS Pro. The answer, which is basically undocumented, can be found by looking at the recently updated documentation on Foreground and background processing in ArcGIS Desktop.
Using the in-memory workspace with background processing .... - Background processing is a separate process from ArcMap or ArcCatalog. These processes cannot share memory (RAM). When a tool is executed, the data it uses must be opened by the background processes. So, an input feature class will be opened directly by the background processes, but layers in ArcMap must follow a different path....
- Most of the Create tools, such as Create File GDB and Create Feature Class take two input parameters (a workspace and a name) to derive a new output. These tools allow you to input in_memory as the workspace. However, when executed in the background, the newly created output will always have the result returned as a location on disk, even if in_memory is used as the workspace. These tools are better used as part of a workflow in ModelBuilder or a Python script tool where the in-memory workspace can be used throughout the entire execution of the tool.
|
It appears, and I say appears because I haven't found good documentation yet, that ArcGIS Pro uses something similar to 'background processing' in ArcGIS Desktop. Unlike ArcGIS Desktop where the user can choose between foreground and background processing under the Geoprocessing options, there is no choice in ArcGIS Pro, or at least that I have found yet.