为什么同行打印之间没有延迟?

时间:2016-08-01 09:12:56

标签: python printing output delay

print 'foo',
time.sleep(1)
print 'bar'

这似乎首先运行time.sleep(1),然后一次打印"foo bar"

但是,在自己的行上打印foobar会在打印语句之间产生预期的延迟:

print 'foo'
time.sleep(1)
print 'bar'

是否有东西会堆叠所有打印语句,直到收到新的换行符?

1 个答案:

答案 0 :(得分:7)

import time import sys print 'foo' sys.stdout.flush() time.sleep(1) print 'bar 默认打印到sys.stdout并且是行缓冲的。你可以在打印语句后每次刷新缓冲区

Warning: More than one text-domain is being used in this theme. This means the theme will not be compatible with WordPress.org language packs.

WARNING: The theme uses the add_shortcode() function. Custom post-content shortcodes are plugin-territory functionality.

We strongly recommend adding a WARNING: Found ini_set in the file library/functions/MCAPI.class.php. Themes should not change server PHP settings.

Line 2829: ini_set('arg_separator.output', '&');
Line 2833: ini_set('arg_separator.output', $orig_sep);

WARNING: library/wp_init.php. User levels were deprecated in 2.0. Please see Roles_and_Capabilities
Line 692: if ( !current_user_can( 'level_5' ) ) {

WARNING: file_put_contents was found in the file library/addons/google-sign-in/cache/Google_FileCache.php File operations should use the WP_Filesystem methods instead of direct PHP filesystem calls.
Line 124: if (! @file_put_contents($storageFile, $data)) {

WARNING: curl_init was found in the file library/addons/google-sign-in/io/Google_CurlIO.php File operations should use the WP_Filesystem methods instead of direct PHP filesystem calls.
Line 94: $ch = curl_init();

WARNING: curl_exec was found in the file library/addons/google-sign-in/io/Google_CurlIO.php File operations should use the WP_Filesystem methods instead of direct PHP filesystem calls.
Line 112: $respData = curl_exec($ch);
Line 119: $respData = curl_exec($ch);

WARNING: .htaccess Hidden Files or Folders found.

REQUIRED: You are not allowed to hide the admin bar.

REQUIRED: The theme uses the register_taxonomy() function, which is plugin-territory functionality.

REQUIRED: The theme uses the register_post_type() function, which is plugin-territory functionality.

REQUIRED: The theme must not used the tags.

REQUIRED: The theme must not call to wp_title().

REQUIRED: The tags can only contain a call to wp_title(). Use the wp_title filter to modify the output

REQUIRED: No reference to add_theme_support( "title-tag" ) was found in the theme.

REQUIRED: wp_get_http() found in the file library/admin/import/class.wordpress-importer.php. Deprecated since version 4.4. Use WP_Http instead.
Line 908: $headers = wp_get_http( $url, $upload['file'] );

REQUIRED: screen_icon() found in the file library/functions/class-tgm-plugin-activation.php. Deprecated since version 3.8.
Line 403: screen_icon( apply_filters( 'tgmpa_default_screen_icon', 'themes' ) );
Line 1599: screen_icon( apply_filters( 'tgmpa_default_screen_icon', 'themes' ) );

REQUIRED: screen_icon() found in the file library/admin/import/class.wordpress-importer.php. Deprecated since version 3.8.
Line 1038: screen_icon();

REQUIRED: library/functions/class-tgm-plugin-activation.php. Themes should use add_theme_page() for adding admin pages.
Line 370: add_submenu_page( $args['parent_slug'], $args['page_title'], $args['menu_ti

REQUIRED: library/admin/theme-settings.php. Themes should use add_theme_page() for adding admin pages.
Line 133: add_submenu_page(

REQUIRED: library/admin/theme-settings.php. Themes should use add_theme_page() for adding admin pages.
Line 122: add_menu_page(

REQUIRED: library/admin/import/theme-import.php. Themes should use add_theme_page() for adding admin pages.

REQUIRED: library/admin/export/theme-export.php. Themes should use add_theme_page() for adding admin pages.

REQUIRED: bloginfo( 'url') was found in the file library/shortcodes/search-form/search-form.php. Use echo esc_url( home_url() ) instead.
Line 120: '>

REQUIRED: Zip file found. Plugins are not allowed in themes. The zip file found was js_composer.zip ultimate_vc_addons.zip.

RECOMMENDED: Screenshot size should be 1200x900, to account for HiDPI displays. Any 4:3 image size is acceptable, but 1200x900 is preferred.

RECOMMENDED: Possible variable $title found in translation function in library/define.php. Translation function calls must NOT contain PHP variables.
Line 333: '><?php _e($title, 'text-domain');?>

RECOMMENDED: Possible variable $sub_title found in translation function in library/define.php. Translation function calls must NOT contain PHP variables.
Line 341: <?php e($subtitle, 'text-domain');?>

RECOMMENDED: Possible variable $portal found in translation function in templates/parts/part-add-item-step1.php. Translation function calls must NOT contain PHP variables.
Line 181: ,__($portal,'text-domain')

RECOMMENDED: Possible variable $offer found in translation function in library/classes/theme-directory-meta.php. Translation function calls must NOT contain PHP variables.
Line 155:

<?php _e($offer, 'text-domain');?>
RECOMMENDED: Possible variable $theme_tso found in translation function in templates/parts/part-single-reviews.php. Translation function calls must NOT contain PHP variables.
Line 27: <?php e($themetso->get('rating_alert_content'), 'text-domain');?>

RECOMMENDED: Possible variable $theme_tso found in translation function in templates/parts/part-single-reviews.php. Translation function calls must NOT contain PHP variables.
Line 15: <?php e($themetso->get('rating_alert_header', __('Total Reviews','text-domain'))

RECOMMENDED: Possible variable $theme_this_taxonomy found in translation function in tag.php. Translation function calls must NOT contain PHP variables.
Line 27: <?php printf( _( '{$themethis_taxonomy} Archives: %s', 'text-domain' ), '' . singl

RECOMMENDED: Possible variable $theme_this_regist found in translation function in library/shortcodes/theme-item-time-line/theme-item-time-line.php. Translation function calls must NOT contain PHP variables.
Line 283: , 'week'  => _(datei18n( 'l', $theme_this_regist ), 'text-domain' )

RECOMMENDED: Possible variable $theme_this_regist found in translation function in library/shortcodes/theme-item-time-line/theme-item-time-line.php. Translation function calls must NOT contain PHP variables.
Line 282: , 'day'   => _( date( 'd', $themethis_regist ), 'text-domain' )

RECOMMENDED: Possible variable $theme_this_regist found in translation function in library/shortcodes/theme-item-time-line/theme-item-time-line.php. Translation function calls must NOT contain PHP variables.
Line 281: , 'month' => _( datei18n( 'F', $theme_this_regist ), 'text-domain' )

RECOMMENDED: Possible variable $theme_this_author found in translation function in templates/parts/part-single-contact.php. Translation function calls must NOT contain PHP variables.
Line 24:

<?php if($theme_this_author->get('user_email')!='') esc_html_e( _('Email', 'text-domain').': '.$themethis_author->get('user_email') );
RECOMMENDED: Possible variable $theme_this_author found in translation function in templates/parts/part-single-contact.php. Translation function calls must NOT contain PHP variables.
Line 23:

<?php if($theme_this_author->get('phone')!='') esc_html_e( _('Phone', 'text-domain').': '.$themethis_author->get('phone') );?></l
RECOMMENDED: Possible variable $theme_custom_item_label found in translation function in templates/parts/part-single-reviews.php. Translation function calls must NOT contain PHP variables.
Line 7: echo apply_filters('theme_shortcode_title', _($themecustom_item_label->get('ratings', 'Ratings'), 'text-domain'), get_

RECOMMENDED: Possible variable $theme_custom_item_label found in translation function in library/functions/callback-get-map-brief.php. Translation function calls must NOT contain PHP variables.
Line 46:

<?php printf('%s : %.1f /%d', _($themecustom_item_label->get('ratings', 'Ratings'), 'text-domain'), (flo
RECOMMENDED: Possible variable $theme_custom_item_label found in translation function in library/dashboard/mypage-add-event.php. Translation function calls must NOT contain PHP variables.
Line 71: ' class='form-control' placeholder='<?php e($themecustom_item_label->get('events', 'Events').' Title', 'text-domain'

RECOMMENDED: Possible variable $theme_custom_item_label found in translation function in library/dashboard/mypage-add-event.php. Translation function calls must NOT contain PHP variables.
Line 48: <?php echo empty($edit)? _('Add '.$themecustom_item_label->get('events', 'Events'), 'text-domain')

RECOMMENDED: Possible variable $theme_custom_item_label found in translation function in library/dashboard/mypage-add-event.php. Translation function calls must NOT contain PHP variables.
Line 48: <?php echo empty($edit)? _('Add '.$themecustom_item_label->get('events', 'Events'), 'text-domain') : _('Edit '.$themecustom_item_label->get('events', 'Events'), 'text-domain')

RECOMMENDED: Possible variable $field found in translation function in library/admin/assets/theme-settings-rating.php. Translation function calls must NOT contain PHP variables.
Line 40: , __($field, 'text-domain')

RECOMMENDED: Possible variable $default found in translation function in library/classes/theme-directory-meta.php. Translation function calls must NOT contain PHP variables.
Line 114: $theme_return = __( $default , 'text-domain' );

RECOMMENDED: Possible variable $cvalue found in translation function in woocommerce/cart/shipping-calculator.php. Translation function calls must NOT contain PHP variables.
Line 53: echo '' . _( eschtml( $cvalue ), 'woocommerce' ) .'';

RECOMMENDED: wp_get_http() found in the file library/admin/import/class.wordpress-importer.php. Deprecated since version 4.4. Use WP_Http instead.
Line 908: $headers = wp_get_http( $url, $upload['file'] );

INFO: Possible Favicon found in header.php. Favicons are handled by the Site Icon setting in the customizer since version 4.3.

INFO: templates/tp-blogs.php The theme appears to use include or require. If these are being used to include separate sections of a template from independent files, thenget_template_part() should be used instead.
Line 18:

INFO: library/functions/callback-theme-map.php The theme appears to use include or require. If these are being used to include separate sections of a template from independent files, then get_template_part() should be used instead.
Line 145: $theme_this_posts_args['include'] = (Array) $theme_this_user_favorite_posts ;

INFO: library/addons/google-sign-in/contrib/Google_ShoppingService.php The theme appears to use include or require. If these are being used to include separate sections of a template from independent files, then get_template_part() should be used instead.
Line 34: * @opt_param string facets.include Facets to include (applies when useGcsConfig == false)
Line 151:

INFO: library/addons/google-sign-in/cache/Google_Cache.php The theme appears to use include or require. If these are being used to include separate sections of a template from independent files, then get_template_part() should be used instead.
Line 18: 
Line 19:

INFO: library/addons/google-sign-in/auth/Google_Verifier.php The theme appears to use include or require. If these are being used to include separate sections of a template from independent files, then get_template_part() should be used instead.
Line 18:

INFO: library/addons/google-sign-in/auth/Google_Signer.php The theme appears to use include or require. If these are being used to include separate sections of a template from independent files, then get_template_part() should be used instead.
Line 18:

INFO: library/addons/google-sign-in/auth/Google_OAuth2.php The theme appears to use include or require. If these are being used to include separate sections of a template from independent files, then get_template_part() should be used instead.
Line 18: 
Line 19: 
Line 20:

INFO: library/addons/google-sign-in/auth/Google_Auth.php The theme appears to use include or require. If these are being used to include separate sections of a template from independent files, then get_template_part() should be used instead.
Line 18: 
Line 19:

INFO: library/addons/google-sign-in/Google_Client.php The theme appears to use include or require. If these are being used to include separate sections of a template from independent files, then get_template_part() should be used instead.
Line 39: 
Line 43: require_once (dirname(FILE) . '/local_config.php');
Line 48: require_once 'service/Google_Model.php';
Line 49: require_once 'service/Google_Service.php';
Line 50: require_once 'service/Google_ServiceResource.php';
Line 51: require_once 'auth/Google_AssertionCredentials.php';
Line 52: require_once 'auth/Google_Signer.php';
Line 53: require_once 'auth/Google_P12Signer.php';
Line 54: require_once 'service/Google_BatchRequest.php';
Line 55: require_once 'external/URITemplateParser.php';
Line 56: require_once 'auth/Google_Auth.php';
Line 57: require_once 'cache/Google_Cache.php';
Line 58: require_once 'io/Google_IO.php';
Line 59: require_once('service/Google_MediaFileUpload.php');

INFO: iframe was found in the file library/functions/process.php iframes are sometimes used to load unwanted adverts and code on your site.
Line 393: , 'html'  => (!empty($theme_attachment_video)? sprintf('', $theme_attachment_v

INFO: iframe was found in the file library/admin/post-meta-box.php iframes are sometimes used to load unwanted adverts and code on your site.
Line 1274: Iframe Input -->
Line 1280: iFrame Code', 'text-domain');?>
Line 1879: , 'html' => (!empty($theme_attachment_video)? sprintf('', $theme_attachment_vi

参考:sys

另请阅读:How to flush output of Python print?