如何使用pexpect在多个文件上运行osm2pgsql?停留在“使用PBF解析器”上。

我正在尝试从多个.pbf文件创建一个SQL表。

我正在使用osm2pgsql将文件加载到远程数据库中,并尝试使用python和pexpect自动执行该过程。

虽然第一个osm2pgsql命令成功运行,但是在打印“使用PBF解析器”之后,后续命令似乎卡住了。

这是我的代码:

child = pexpect.spawn('bash',timeout=20000)
child.logfile_read = sys.stdout.buffer # show output for debugging

filenames = os.listdir('pbf_files')
for i,filename in enumerate(filenames):

    print(filename)
    upload_command_args = [
        "pbf_files/{}".format(filename),"-l","-s","-d",db_name,"-U",username,"-P",port,"-H",host,"-W","-S","default.style","-r","pbf","-p",table_name,"--hstore",]

    # Need the append option since table already exists after first iteration
    if i > 0:
        upload_command_args = upload_command_args + ["--append"]

    print(upload_command_args)
    child.sendline('osm2pgsql ' + ' '.join(upload_command_args))
    child.expect('Password:')
    child.sendline('myFakePass')
    child.expect('Osm2pgsql took .+ overall')

child.close()
sys.exit(child.status)

第0次迭代正常运行,但第1次迭代在shell打印后卡住了:

Reading in file: pbf_files/my_partition_1.pbf
Using PBF parser.

我误解了.expect()的工作原理吗?

waruut 回答:如何使用pexpect在多个文件上运行osm2pgsql?停留在“使用PBF解析器”上。

追加花费的时间比初始插入要长得多。您可能想尝试使用-C并使用合理数量的缓存(默认值为800MB)。另外,我们谈论的是初次插入后的几个小时。因此,也许您想确保始终先插入最大的文件。如果文件非常大,则也可以使用--slim来确保缓存耗尽时不会崩溃。

本文链接:https://www.f2er.com/2489282.html

大家都在问