Git bash不显示python的实时更新

问题描述

我的Git bash不显示Python的实时输出。例如,如果我尝试打印“正在加载”,然后发出HTTP请求,然后再次打印出一些内容,那么我的git bash会一次显示所有内容

我试图启动Django runserver,这就是我得到的:

Watching for file changes with StatReloader

它一直显示这一时间,所以我决定重新运行该命令。当我按下CTRL + C时,我得到了:

Performing system checks...

System check identified no issues (0 silenced).

You have 18 unapplied migration(s). Your project may not work properly until you apply the migrations 
for app(s): admin,auth,contenttypes,sessions.
Run 'python manage.py migrate' to apply them.
October 03,2020 - 23:08:15
Django version 3.1.2,using settings 'first_django_project.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CTRL-BREAK.

这意味着服务器实际上已经启动,但是bash却不显示任何内容。我该如何解决

编辑: 由于你们中的许多人一直在索要示例文件,因此我创建了一个文件来演示该问题:

import time

print('#1 Statement 1')
time.sleep(10)

print('#2 Statement 2')
time.sleep(10)

print('#3 Statement 3')

文件的理想输出应该是立即显示#1,然后在10s之后显示#2,然后在10s之后显示#3,然后执行完成。

但是,在我的重击中,我29秒钟都没有得到任何输出。在30秒时,我立即获得所有三个语句作为输出,并且执行停止。

在Django示例中,当服务器运行时,bash上也没有看到任何东西,但是当我按下CTRL + C时,执行被中断,并且我从'Performing系统。 。 。”直到结束。

我希望我的问题很清楚。谢谢。

解决方法

这是python脚本吗?使用打印后尝试冲洗,它应该可以工作。

import time
from selenium import webdriver
from selenium.webdriver.common.keys import Keys

# loading the webpage
browser = webdriver.Chrome()
browser.get("https://instagram.com")
time.sleep(1)

# finding essential requirements
user_name = browser.find_element_by_name("username")
password = browser.find_element_by_name("password")
login_button = browser.find_element_by_xpath("//button [@type = 'submit']")

# filling out the user name box
user_name.click()
user_name.clear()
user_name.send_keys("username")

# filling out the password box
password.click()
password.clear()
password.send_keys("password")

# clicking on the login button
login_button.click()
time.sleep(3)

# information save permission denial
not_now_button = browser.find_element_by_xpath("//button [@class = 'sqdOP yWX7d    y3zKF     ']")
not_now_button.click()
time.sleep(3)

# notification permission denial
not_now_button_2 = browser.find_element_by_xpath("//button [@class = 'aOOlW   HoLwm ']")
not_now_button_2.click()
time.sleep(3)

# finding search box and searching + going to the page
search_box = browser.find_element_by_xpath('//input [@placeholder="Search"]')
search_box.send_keys("sb else's page")
time.sleep(3)
search_box.send_keys(Keys.RETURN)
search_box.send_keys(Keys.RETURN)
time.sleep(3)

# opening ((followers)) list
followers = browser.find_element_by_xpath('//a [@class="-nal3 "]')
followers.click()
time.sleep(10)

# following each follower
follower = browser.find_elements_by_xpath('//button [@class="sqdOP  L3NKy   y3zKF     "]')


browser.close()