Repository: mlflow/mlflow

Issue:
[BUG] - `mlruns` directory automatically created without doing anything
### Willingness to contribute
The MLflow Community encourages bug fix contributions. Would you or another member of your organization be willing to contribute a fix for this bug to the MLflow code base?

- [ ] Yes. I can contribute a fix for this bug independently.
- [x] Yes. I would be willing to contribute a fix for this bug with guidance from the MLflow community.
- [ ] No. I cannot contribute a bug fix at this time.

### System information
- **Have I written custom code (as opposed to using a stock example script provided in MLflow)**: No
- **OS Platform and Distribution (e.g., Linux Ubuntu 16.04)**: MacOS 10.15.4 and Linux
- **MLflow installed from (source or binary)**: conda-forge
- **MLflow version (run ``mlflow --version``)**: 1.11
- **Python version**: tested on 3.8 and 3.7
- **npm version, if running the dev UI**:
- **Exact command to reproduce**: `import mlflow`

### Describe the problem
With version `1.11`, simply importing `mlflow` results in an `mlruns` directory being created.

### Code to reproduce issue
Here is an anaconda env:
```yaml
name: ml
channels:
  - conda-forge
dependencies:
  - mlflow=1.11
```

Activating (`conda activate ml`) and then importing `mlflow` causes the `mlruns` directory from being created
```python
import mlflow
print(f"mlflow version {mlflow.__version__}")
```
Prints `mlflow version 1.11.0`.

This is BAD because it means that any project that uses `mlflow` in its backend creates these `mlruns` directories all over the place. In my specific example, I have `mlflow` as a dependency and these directories are created within my test suite.

Note that even running `mlflow --version` in the terminal results in the `mlruns` directory being created.

My proposed solution is to not create this directory by default.

### What component(s), interfaces, languages, and integrations does this bug affect?
Components 
- [ ] `area/artifacts`: Artifact stores and artifact logging
- [ ] `area/build`: Build and test infrastructure for MLflow
- [ ] `area/docs`: MLflow documentation pages
- [ ] `area/examples`: Example code
- [ ] `area/model-registry`: Model Registry service, APIs, and the fluent client calls for Model Registry
- [ ] `area/models`: MLmodel format, model serialization/deserialization, flavors
- [ ] `area/projects`: MLproject format, project running backends
- [ ] `area/scoring`: Local serving, model deployment tools, spark UDFs
- [ ] `area/server-infra`: MLflow server, JavaScript dev server
- [x] `area/tracking`: Tracking Service, tracking client APIs, autologging

Interface 
- [ ] `area/uiux`: Front-end, user experience, JavaScript, plotting
- [ ] `area/docker`: Docker use across MLflow's components, such as MLflow Projects and MLflow Models
- [ ] `area/sqlalchemy`: Use of SQLAlchemy in the Tracking Service or Model Registry
- [ ] `area/windows`: Windows support

Language 
- [ ] `language/r`: R APIs and clients
- [ ] `language/java`: Java APIs and clients
- [ ] `language/new`: Proposals for new client languages

Integrations
- [ ] `integrations/azure`: Azure and Azure ML integrations
- [ ] `integrations/sagemaker`: SageMaker integrations
- [ ] `integrations/databricks`: Databricks integrations



Discussion:
@tmcclintock Thanks for reporting this. I was able to reproduce the issue.

commands to repro:

```
mkdir temp
cd temp
pip install "mlflow==1.11.0"
echo "import mlflow" > a.py
python a.py
ls
```

output:

```
a.py	mlruns
```

EDIT:

Confirmed the error doesn't occur in mlflow 1.10.0
I investigated the error by inserting `raise Exception` in `FileStore.__init__` like below:

![Screen Shot 2020-09-11 at 14 49 20](https://user-images.githubusercontent.com/17039389/92869751-1d015e00-f43e-11ea-82b5-805e5780de7d.png)


Here's the stack trace.

```
Traceback (most recent call last):
  File "/Users/harutakakawamura/Desktop/repositories/mlflow/mlflow/tensorflow.py", line 583, in _flush_queue
    client = mlflow.tracking.MlflowClient()
  File "/Users/harutakakawamura/Desktop/repositories/mlflow/mlflow/tracking/client.py", line 55, in __init__
    self._tracking_client = TrackingServiceClient(final_tracking_uri)
  File "/Users/harutakakawamura/Desktop/repositories/mlflow/mlflow/tracking/_tracking_service/client.py", line 39, in __init__
    self.store = utils._get_store(self.tracking_uri)
  File "/Users/harutakakawamura/Desktop/repositories/mlflow/mlflow/tracking/_tracking_service/utils.py", line 127, in _get_store
    return _tracking_store_registry.get_store(store_uri, artifact_uri)
  File "/Users/harutakakawamura/Desktop/repositories/mlflow/mlflow/tracking/_tracking_service/registry.py", line 38, in get_store
    return builder(store_uri=store_uri, artifact_uri=artifact_uri)
  File "/Users/harutakakawamura/Desktop/repositories/mlflow/mlflow/tracking/_tracking_service/utils.py", line 81, in _get_file_store
    return FileStore(store_uri, store_uri)
  File "/Users/harutakakawamura/Desktop/repositories/mlflow/mlflow/store/tracking/file_store.py", line 131, in __init__
    raise Exception
```

Looks like the `mlruns` folder is created when import the tensorflow flavor.

Resolving patch:
diff --git a/mlflow/tensorflow.py b/mlflow/tensorflow.py
--- a/mlflow/tensorflow.py
+++ b/mlflow/tensorflow.py
@@ -587,9 +587,6 @@ def _flush_queue():
     _metric_queue = []
 
 
-atexit.register(_flush_queue)
-
-
 def _add_to_queue(key, value, step, time, run_id):
     """
     Add a metric to the metric queue. Flush the queue if it exceeds
@@ -828,6 +825,8 @@ def autolog(every_n_iter=100):
     global _LOG_EVERY_N_STEPS
     _LOG_EVERY_N_STEPS = every_n_iter
 
+    atexit.register(_flush_queue)
+
     if LooseVersion(tensorflow.__version__) < LooseVersion("1.12"):
         warnings.warn(
             "Could not log to MLflow. Only TensorFlow versions"


Test patch: