Question: I have a short script which reads 1,048,574 records out of a CSV with two columns, and puts them into two lists, one for each column. So each list should end up with 1,048,574 elements.

In PyCharm, this works fine. In the console, the program hangs around 1,048,345.

I can't figure it out. Both are using the same Python, 3.6.5.

Here is the script:

```
import csv

xtime = []
voltage = []

count = 0
with open ('audio2.csv', newline='') as csvfile:
    reader = csv.reader(csvfile)
    for row in reader:
        xtime.append(row[0])
        voltage.append(row[1])
        print(count)
        count += 1
    print('finished reading')

```

Each line of the CSV looks like `-0.000951453,-1.56` and there are 1,048,574 lines. PyCharm prints `finished reading` at the end, but GitBash just hangs after printing `1048345`.

What could be the problem?

Answer: 
**if you are fetching data from API, then the task is async** means it will call the next steps even without completing API request, there is no data in the data source if you apply paginator without data definitely paginator won't work. if you console.log(this.paginator.paginator) you will get undefined, means your data source is not initialized, so you are not able to apply paginator to the data source

**To make it work, always assign data and paginator respectively after completing API requests.**

```
    dataSource = new MatTableDataSource();
    @ViewChild(MatPaginator) paginator: MatPaginator;

    ngOnInit(){
    yourService.getData().subscribe(
        (data)=>{
           this.datasource.data = data;
           this.dataSource.paginator = this.paginator;
                },
        (error)=>{}
       );
    }

```

// note always keep `<mat-paginator> after <mat-table>`
Please try to initialize the MATPAGINATOR and MATSORT as follows and this worked for me.

```
public dataSource = new MatTableDataSource([]);
@ViewChild(MatSort) matSort: MatSort;

private paginator: MatPaginator;
private sort: any;

@ViewChild(MatPaginator) set matPaginator(mp: MatPaginator) {
    this.paginator = mp;
    this.setDataSourceAttributes();
  }

  @ViewChild(MatSort) set content(content: ElementRef) {
    this.sort = content;
    if (this.sort) {
      this.dataSource.sort = this.sort;
    }
  }

  setDataSourceAttributes() {
    this.dataSource.paginator = this.paginator;
    this.dataSource.sort = this.sort;
  }

```

Above code checks for the paginator and sort variables and will gets set when they are undefined.
Also no need to add #paginator in your HTML file.

Thanks and Regards,
Kishore Kumar. K