Accessing a database from a multithreaded application

2005-11-22 Thread Alan Kemp
Hi,

I have a problem that is half python, half design.  I have a
multithreaded network server working, each client request spawns a new
thread which deals with that client for as long as it is connected
(think ftp style rather than http style connections here).  Each thread
gets passed a reference to the main server to access things like the
list of connected clients, global data, etc.

Now I want to add a database to store usernames and other user data.  I
grabbed a copy of pysqlite2 which I have used successfully in the past
in single-threaded applications.  My initial plan was for the server to
create a single connection and cursor and then just use some sort of
mutex to control access to it from the various threads.  However,
apparently you can only access the cursor from the thread on which it
was created...

Can someone suggest a better (ie, valid) strategy for this?  Should I
be using a Queue to make a list of db requests/results to get accross
the thread boundary (erg, that sounds nasty)?  Should each client
thread create its own connection/cursor to the database?  Would that
even work, wont there be locking issues?

Any suggestions or pointers in the direction of more information would
be greatly appreciated.

Thanks for your time,

Alan

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Put a url in a browsers address bar

2005-08-18 Thread Alan Kemp

On Thu, 18 Aug 2005 12:01:16 -0400, Colin Gillespie  
<[EMAIL PROTECTED]> wrote:

> I would like to place a url in my browsers address bar, then execute.
> How can do this?
>
> e.g.
>
> def goToGoogle():
>   url = "www.google.com"
>   b = openBrowser()
>   b.goToUrl(url)  
>   return True
>

def goToGoogle():
import webbrowser
webbrowser.open("www.google.com");

Alan
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: (OT) Is there something that people can use instead of full blown Python to run Python programs?

2005-08-18 Thread Alan Kemp
On Thu, 18 Aug 2005 12:38:30 -0400, Gregory PiƱero <[EMAIL PROTECTED]>  
wrote:

> I'm no expert, but I'm guessing you could compile a python with less
> libraries. I bet that would slim it down a lot.
>
> -Greg
>
>
> On 8/18/05, Nathan Pinno <[EMAIL PROTECTED]> wrote:
>>
>> Hi all,
>>  Is there something besides the full blown version of Python that people
>> can use to run Python programs, or do they have to use the full blown
>> version of it?
>>  Thanks,
>> Nathan


Alternativly, use something like  
http://starship.python.net/crew/theller/py2exe/ to convert into a native  
executable.  Of course this depends on whether your question was intended  
as "how can people run some python script", or "how can people run my  
python script".

Alan
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: last line chopped from input file

2005-08-21 Thread Alan Kemp
On Sun, 21 Aug 2005 13:41:14 -0400, Eric Lavigne <[EMAIL PROTECTED]>  
wrote:

>> A shorter python program would be:
>>
>>   os.command("debug\\curve-fit output.txt")
>
> I tried this program:
>   import os
>   os.command("debug\\curve-fit output.txt")
>
> My error message is:
>   AttributeError: 'module' object has no attribute 'command'
>
> I also could not find os.command in the help files. My Python version
> is 2.4 (latest is 2.4.1, just a bug-fix release).
>

I imagine thats was a typo for:

>>> os.system("debug\\curve-fit output.txt")

Alan


-- 
http://mail.python.org/mailman/listinfo/python-list