Hang in Python script using SQLAlchemy and multiprocessing

后端 未结 4 1881
北海茫月
北海茫月 2021-01-05 06:48

Consider the following Python script, which uses SQLAlchemy and the Python multiprocessing module. This is with Python 2.6.6-8+b1(default) and SQLAlchemy 0.6.3-3 (default)

4条回答
  •  长情又很酷
    2021-01-05 07:36

    The TypeError: ('__init__() takes at least 4 arguments (2 given) error isn't related to the sql you're trying to execute, it has to do with how you're using SqlAlchemy's API.

    The trouble is that you're trying to call execute on the session class rather than an instance of that session.

    Try this:

    session = Session()
    session.execute("COMMIT; BEGIN; TRUNCATE foo%s; COMMIT;")
    session.commit()
    

    From the docs:

    It is intended that the sessionmaker() function be called within the global scope of an application, and the returned class be made available to the rest of the application as the single class used to instantiate sessions.

    So Session = sessionmaker() returns a new session class and session = Session() returns an instance of that class which you can then call execute on.

提交回复
热议问题