mysql - python write output to different fifo pipe file? -
I am trying to split a large text file into two parts, and two parts are separated into two separate mysql I am dumping in the table. I do this in Python, inspect the text line by line and classify each line by category code.
Now after dividing the text, how do I pipe them into two separate FIFO files, so that I can use these pipes for mysql client tool?
I think you can import two separate, and apparently simultaneous MySQL Looking to create pipes are the same Python script?
Although it is not impossible to do this, through shell redirection, it will be painful. Your Python script is somehow to pass file files in your pipe to a shell, so your shell script can redirect those file descriptors to MySQL commands.
This is a very easy solution to do in python modules.
I do not know the tools and syntax that you expect to use to bulk load; What you said is that if you want to "pipe" it, then I just assume that this is the mysqlimport
command mentioned in the answer to hbristow, and it stdin as a filename In the -
handling through the General Unix Conference; Since this is just to show the real interesting part, it does not matter anyway.
Such as: imported as imported ('giantfile.txt') as popen, stdin args = ['mysqlimport', 'imported1' from Popup subprocess, Popen My_db_name with 'popen' (args, stdin = PIPE) as (args, stdin = PIPE) for row in f: data = parse (line) if_in_import2 (data): import2.stdin.write (Make_sql (data)) Other: import1.stdin.write (make_sql (data))
We have made two separate child processes, each of its own separate stdin
with pipes, and we can write them in any other file the same way.
You would expect import1 .stdin.close ()
and import2.stdin.close ()
if mysqlimport
To exit the input file that is close to / eof really waits before it.
If you are using Python 2.4-2.7, then you should install and use e-backport if you have any reason (or if you are using Python 3.0-3.1 And can not upgrade for any reason), you can not use the statement with
statement here; Instead, you need to explicitly close
pipes and wait
processes.
Comments
Post a Comment