有一天在 PyCharm 中搞弄 Python 的时候,遇到了一个很傻的问题。也就是说,当我尝试在名为 的文件中运行一个简单的脚本时abc.py,我收到一个错误。我尝试直接从终端运行相同的文件,看起来不错。
abc.py
print("Hello world")
Run Code Online (Sandbox Code Playgroud)
输出:
/Users/.../venv/bin/python /Users/.../abc.py
Fatal Python error: init_sys_streams: can't initialize sys standard streams
Traceback (most recent call last):
File "/usr/local/Cellar/python/3.7.7/Frameworks/Python.framework/Versions/3.7/lib/python3.7/io.py", line 52, in <module>
File "/Users/.../abc.py", line 1, in <module>
RuntimeError: lost sys.stdout
Process finished with exit code 134 (interrupted by signal 6: SIGABRT)
Run Code Online (Sandbox Code Playgroud)
只是出于好奇,这里有什么问题?
编辑:为什么它只在从 PyCharm 运行时发生,而不是从终端运行时发生?
我有带有 Spring Batch 框架的 Spring Boot 应用程序。我的目标很简单——同时运行某些工作。比方说,我希望能够同时运行 15 个线程并拒绝每个多余的线程。这是我的配置类:
import org.springframework.batch.core.Job;
import org.springframework.batch.core.Step;
import org.springframework.batch.core.configuration.JobRegistry;
import org.springframework.batch.core.configuration.annotation.EnableBatchProcessing;
import org.springframework.batch.core.configuration.annotation.JobBuilderFactory;
import org.springframework.batch.core.configuration.annotation.StepBuilderFactory;
import org.springframework.batch.core.configuration.support.JobRegistryBeanPostProcessor;
import org.springframework.batch.core.launch.JobLauncher;
import org.springframework.batch.core.launch.support.SimpleJobLauncher;
import org.springframework.batch.core.repository.JobRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.task.TaskExecutor;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
@Configuration
@EnableBatchProcessing
public class GeneratingReportJobConfiguration {
@Autowired
private GeneratingReportTask task;
@Autowired
private JobRepository jobRepository;
@Autowired
private JobBuilderFactory jobBuilderFactory;
@Autowired
private StepBuilderFactory stepBuilderFactory;
@Bean
public JobRegistryBeanPostProcessor jobRegistryBeanPostProcessor(JobRegistry jobRegistry) {
JobRegistryBeanPostProcessor jobRegistryBeanPostProcessor = new JobRegistryBeanPostProcessor();
jobRegistryBeanPostProcessor.setJobRegistry(jobRegistry);
return jobRegistryBeanPostProcessor;
}
@Bean
public TaskExecutor taskExecutor() …Run Code Online (Sandbox Code Playgroud)