Go: fatal error: all goroutines are asleep - deadlock
<p>I have a text file with just one line of words in it. I want to store all of those words separately in a channel, and then extract them all from the channel and print them one by one. I have the following code:</p>

<pre><code>func main() {
    f, _ := os.Open("D:\\input1.txt")
    scanner := bufio.NewScanner(f)
    file1chan := make(chan string)   
    for scanner.Scan() {
        line := scanner.Text()

        // Split the line on a space
        parts := strings.Fields(line)

        for i := range parts {   
            file1chan &lt;- parts[i]
        }    
    }
    print(file1chan)
}

func print(in &lt;-chan string) {
    for str := range in {
        fmt.Printf("%s\n", str)
    }
}
</code></pre>

<p>But when i run it i get the following error: </p>

<blockquote>
  <p>fatal error: all goroutines are asleep - deadlock!</p>
  
  <p>goroutine 1 [chan send]: main.main()</p>
</blockquote>

<p>I tried looking it up online but i still couldn't manage to fix it. Could anybody please tell me why this is happening and how i can go about fixing it?</p>

<p>Thanks!</p>