blocking all threads

2008-09-29 Thread Alexandru Mosoi
how can I block all threads for a specific amount of time? (i need to sleep whole process for testing purposes). i thought of accessing GIL and sleep for some amount of time, but I don't know how to do this and whether GIL is recursive. -- http://mail.python.org/mailman/listinfo/python-list

generator exceptions

2008-09-19 Thread Alexandru Mosoi
i have a generator that raises an exception when calling next(), however if I try to catch the exception and print the traceback i get only the line where next() was called while True: try: iterator.next() except StopIteration: break except Exception, e: traceback.print_exc() h

Re: derived classes and __getattr__

2008-09-05 Thread Alexandru Mosoi
On Sep 5, 1:13 pm, Peter Otten <[EMAIL PROTECTED]> wrote: > Alexandru  Mosoi wrote: > > On Sep 5, 11:47 am, Peter Otten <[EMAIL PROTECTED]> wrote: > >> Alexandru Moșoi wrote: > >> > i'm facing the following problem: > > >> > class Bas

Re: derived classes and __getattr__

2008-09-05 Thread Alexandru Mosoi
On Sep 5, 11:47 am, Peter Otten <[EMAIL PROTECTED]> wrote: > Alexandru Moșoi wrote: > > i'm facing the following problem: > > > class Base(object): > >   def __getattr__(self, attr): return lambda x: attr + '_' + x > > > def dec(callable): > >   return lambda *args: 'dec_' + callable(*args) > > > c

how do I stop SocketServer()?

2008-08-27 Thread Alexandru Mosoi
supposing that I have a server (an instance of SocketServer()) that waits for a connection (ie is blocked in accept()) and in another thread i want to stop the server, how do I do that? -- http://mail.python.org/mailman/listinfo/python-list

Re: use of Queue

2008-08-27 Thread Alexandru Mosoi
On Aug 27, 12:45 pm, Alexandru Mosoi <[EMAIL PROTECTED]> wrote: > how is Queue intended to be used? I found the following code in python > manual, but I don't understand how to stop consumers after all items > have been produced. I tried different approaches but all of the

Re: use of Queue

2008-08-27 Thread Alexandru Mosoi
On Aug 27, 2:54 pm, Jeff <[EMAIL PROTECTED]> wrote: > Queue raises an Empty exception when there are no items left in the > queue.  Put the q.get() call in a try block and exit in the except > block. Wrong. What if producer takes a long time to produce an item? Consumers will find the queue empty

Re: use of Queue

2008-08-27 Thread Alexandru Mosoi
On Aug 27, 1:06 pm, Gerhard Häring <[EMAIL PROTECTED]> wrote: > Alexandru Mosoi wrote: > > how is Queue intended to be used? I found the following code in python > > manual, but I don't understand how to stop consumers after all items > > have been produced. I tried

use of Queue

2008-08-27 Thread Alexandru Mosoi
how is Queue intended to be used? I found the following code in python manual, but I don't understand how to stop consumers after all items have been produced. I tried different approaches but all of them seemed incorrect (race, deadlock or duplicating queue functionality) def worker():

atomic increment

2008-08-26 Thread Alexandru Mosoi
how can i do an atomic read+increment? something like with lock: old = atomic_int atomic_int += 1 but in one operation -- http://mail.python.org/mailman/listinfo/python-list

logging exceptions

2008-08-26 Thread Alexandru Mosoi
why doesn't logging throw any exception when it should? how do I configure logging to throw exceptions? >>> try: ... logging.fatal('asdf %d', '123') ... except: ... print 'this line is never printed' ... Traceback (most recent call last): File "/Library/Frameworks/Python.framework/Versions/2

passing arguments to exec

2008-08-25 Thread Alexandru Mosoi
i want to execute a python script using exec open('script.py'). how do I pass arguments? -- http://mail.python.org/mailman/listinfo/python-list

Re: cathing uncaught exceptions

2008-08-19 Thread Alexandru Mosoi
On Aug 18, 6:02 pm, Alexandru Mosoi <[EMAIL PROTECTED]> wrote: > how can I catch (globally) exception that were not caught in a try/ > catch block in any running thread? i had this weird case that an > exception was raised in one thread, but nothing was displayed/logged. I foun

Re: cathing uncaught exceptions

2008-08-18 Thread Alexandru Mosoi
On Aug 18, 6:18 pm, Paul McGuire <[EMAIL PROTECTED]> wrote: > On Aug 18, 10:02 am, Alexandru  Mosoi <[EMAIL PROTECTED]> wrote: > > > how can I catch (globally) exception that were not caught in a try/ > > catch block in any running thread? i had this weird case that

cathing uncaught exceptions

2008-08-18 Thread Alexandru Mosoi
how can I catch (globally) exception that were not caught in a try/ catch block in any running thread? i had this weird case that an exception was raised in one thread, but nothing was displayed/logged. -- http://mail.python.org/mailman/listinfo/python-list

Re: execute another python script

2008-08-18 Thread Alexandru Mosoi
On Aug 18, 11:34 am, Fredrik Lundh <[EMAIL PROTECTED]> wrote: >  >>> import sys, subprocess >  >>> subprocess.call([sys.executable, "-c", "print 'hello'"]) > hello > 0 10x :). exactly what I was looking for. -- http://mail.python.org/mailman/listinfo/python-list

execute another python script

2008-08-18 Thread Alexandru Mosoi
how do I execute another python script under a different process? I want the script to be run using the same interpretoer as the one running current script. I tried using os.execlp but I don't know how to get the name/path of the interpreter. -- http://mail.python.org/mailman/listinfo/python-list

Re: python interpreter

2008-08-14 Thread Alexandru Mosoi
On Aug 12, 7:46 pm, "Calvin Spealman" <[EMAIL PROTECTED]> wrote: > The best answer is: Don't do that! > > That isn't how you test things. Write test scripts, probably using the > unittest framework. You'll save yourself time and trouble having > easily reproducible tests. Many people suggested relo

Re: callbacks in python

2008-08-13 Thread Alexandru Mosoi
On Aug 14, 12:02 am, Fredrik Lundh <[EMAIL PROTECTED]> wrote: > your use of the word "callback" is a bit unusual, and your example isn't > valid Python code, but it looks as if functools.partial might be what > you need: > >      http://docs.python.org/lib/module-functools.html my current implemen

callbacks in python

2008-08-13 Thread Alexandru Mosoi
does anyone know a nice implementation of callbacks in python? i have issues mixing named & unamed parameters. i want build a callback over a function such that some parameters are passed when callback is created and the rest are passed when the function is called. example: callback = Callback(fun

decorating base methods

2008-08-13 Thread Alexandru Mosoi
I want to derive a base class, such that some methods are decorated. The only thing I have in mind is: class Base(object): def A(self, x): pass def B(self, y): pass class Derived(Base): @decorator def A(self, x): Base.A(self, x) Is this correct approach? How can avoid call to Base.A(...

python interpreter

2008-08-12 Thread Alexandru Mosoi
I'm using python's interpreter's to run various commands (like a normal shell). However if sources are modified changes are not reflected so I have to restart interpreter. Is there any way to avoid restarting this? example: import blah blah.Blah() # ... blah.Blah() changed blah.Blah() # ... new