Multiprocessing process termination
Sturla Molden
sturla.molden at gmail.com
Wed Dec 31 16:10:50 EST 2014
Why not use a multiuser database server instead of trying to make one? You
do not have the resources to a better job on your own. You know where to
find Firebird SQL, MariaDB, MySQL, PostegreSQL, IBM DB2, Oracle, etc.
Personally I prefer Firebird because like SQLite the database is stored in
a file. Another nice way to get the database in a file is to run it in an
Oracle VirtualBox VM.
SQLite also allows multiple connections, by the way, but it does not scale
very well.
Regards,
Sturla
Charles Hixson <charleshixsn at earthlink.net> wrote:
> In order to allow multiple processes to access a database (currently
> SQLite) I want to run the process in a separate thread. Because it will
> be accessed from multiple processes I intent to use Queues for shifting
> messages back and forth. But none of the individuals processes will
> know when all of the others are through. It there a way to properly
> close the database, or does it need to be done from the parent process?
>
> What I want to do is detect that a request to shutdown the Process has
> been received, and then execute a close procedure that cleans things up
> and shutdown. Terminate is the obvious procedure to use, but that comes
> with a warning not to use it if there is an queue attached (and without
> defining attached).
> OTOH, since the queue will never be read after the process has been
> shutdown, perhaps rendering it unusable is the proper thing.
>
> Could someone comment on this step of the design?
>
> The basic idea is:
>
> class handledb(Process):
> def __init__(self, q, otherstuff):
> self.q = q
>
> def run(self, msg):
> while (true):
> if self.q.empty():
> sleep(someamountoftime)
> else:
> while (not self.q.empty()):
> read and parse message
> if message says to shutdown: self.shutdown()
>
> def shutdown(self):
> close things down
> ?? terminate ?? <<-- should this be done
> while q is live?
More information about the Python-list
mailing list