On 06/05/2010 08:06 PM, Az wrote:
> Cheers!
>
> Creating a new instance of my mapped class and settings, manually.
> Gotcha. I think this will be an easier solution for me.
>
> Nah, I'm not in a web framework.
>
> Additional Q:
>
> +++
>
> Currently, my database is being stored in memory and it's fine like
> that since a) my data isn't very expansive and b) I'm running the
> program (python Main.py) from a command line where I can just comment
> out various functions in my Main file. However, I'm now designing a
> GUI for my code where I want to be able to call each function
> manually. Now, all functions that reference the session will reference
> "session" I defined as:
>
> Session = sessionmaker(bind=engine)
> session = Session()
>
> Thus after I run my finish my monteCarloBasic (defined way up at the
> top), I'd probably hit another button that would do what I did for
> CODE 2, i.e.
>
> def checkFor4545(trials):
> sid = 4545
> print sid
> project_id_list = list(students[sid].preferences)
> for project_id in project_id_list
> gotcha =
> session.query(SimAllocation).filter(SimAllocation.student_id ==
> sid).filter(PP.SimAllocation.alloc_proj == project_id).count()
> print project_id, gotcha/trials
>
> This basically counts the number of times student 4545 got each of his
> projects for entire Monte-Carlo simulation and prints the average over
> the trials.
>
> So basically when I'm in command line mode and go "python Main.py" my
> Main looks like:
>
> trials = 100
> monteCarloBasic(trials)
> checkFor4545(trials)
>
> So those will run one after the other.
>
> Now when I've got a GUI, I'll have the Monte-Carlo run separately and
> then afterwards, hit a button that corresponds to
> 'checkFor4545(trials)'. Now, the reason I used SQLAlchemy in the first
> place (besides the general usefulness of SQL) is for data persistence.
> Will 'checkFor4545(trials)' display the same output as it would if it
> were run serially from Main.py? Will it reference the same "session"?
> (Probably a question you'll want to slap your forehead over, but I
> just want to verify I've got my understanding correct).
>
I see nothing that indicates that they would NOT see the same session,
but I do have some comments:
* GUIs usually run long tasks in background threads to keep the UI
responsive. If you were to do this, you would not want to use a
single global session, because sharing a session between threads
is a big no-no.
* I'm concerned what the call to resetData does. If it resets
student-project associations, then could it end up deleting the
temp_allocs you just added in that trial?
* What should happen if you run monteCarloBasic multiple times? It
seems like you would get duplicate primary keys on SimAllocation
rows after the 1st call.
> Additionally, when I save to a physical database file, what happens
> everytime I run monteCarloBasic(trials) (since it writes to the
> database). Will it rewrite it every time? Or will it keep appending to
> it?
>
I don't see anything that would indicate rewriting the database in the
code that you have shown (except maybe as a side-effect of your
resetData function that I noted above). Also, you may get duplicate
primary key errors like I mentioned above.
-Conor
--
You received this message because you are subscribed to the Google Groups
"sqlalchemy" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/sqlalchemy?hl=en.