stop thread from outside 'run'

2012-06-05 Thread Prashant
Hi,

I am using tornado web socket server to communicate between python(server) and 
browser(client). To mimic the behavior of sending data to client and get 
results back, I am using threaded approach:

class JobThread(threading.Thread):
""
def __init__(self, target):
""
super(JobThread, self).__init__()
self.target = target
self.res = None
self.stoprequest = threading.Event()
self.start()
self.join()
# Execution stops here and wait
return self.result()

def run(self):
""" Start this thread """
self.target()
while not self.stoprequest.isSet():
print "running..."

def result(self):
""
return self.res

def kill(self, result):
""" Kill this thread """
self.res = result
self.stoprequest.set()

def ReceiveData(message):
""
global t
print str(message)
t.kill(message)

def SendData(data_string):
""
sendMessageWS(data_string)

result = JobThread(partial(SendData, data_string))

As soon as jobThread instance starts it sends data to websocket and wait for 
client to response. Client is sending back results but 'ReceiveData' is not 
getting called because of infinite loop in 'run' method. The only way you can 
stop the thread is from outside when "ReceiveData" executes and kill the 
threaded instance 't'. 

Any pointers?
-- 
http://mail.python.org/mailman/listinfo/python-list


Another non blocking method in thread

2012-06-10 Thread Prashant
Hi,

I have created a very simple client-server model using sockets. Server is 
created by sub classing threading.thread. The 'run' method is continuously 
listening for client's response. When server send a string to client, client 
response back by changing that string into uppercase.
I would like to synchronize send and receive. For example:

def sendmsg(self, msg):
self.client.send(msg)
#wait until next msg is received in 'run'
return self.response

I tried using a while loop for waiting but it's blocking the 'run' method. 
Don't know much about threading event and lock and if they can help me here.

Any pointers?

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


post init call

2012-06-18 Thread Prashant
class Shape(object):
def __init__(self, shapename):
self.shapename = shapename


def update(self):
print "update"

class ColoredShape(Shape):
def __init__(self, color):
Shape.__init__(self, color)
self.color = color
print 1
print 2
print 3
self.update()

User can sub-class 'Shape' and create custom shapes. How ever user must call 
'self.update()' as the last argument when ever he is sub-classing 'Shape'.
I would like to know if it's possible to call 'self.update()' automatically 
after the __init__ of sub-class is done?

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


ImportError: No module named getopt

2006-11-23 Thread prashant
I am running a python script which has the line

import getopt, sys, os, re, string

And i get the error

ImportError: No module named getopt

Could you please point out a possible solution for this?

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


Re: ImportError: No module named getopt

2006-11-23 Thread prashant
Thanks for the reply,
I am actually using Cygwin to run a python script.
I have python 2.5 installed. But when i ran the command mentioned by
you... I see that it is looking in the wrong directories... how can i
change these look up directories?


Fredrik Lundh wrote:
> "prashant" wrote:
>
> >I am running a python script which has the line
> >
> > import getopt, sys, os, re, string
> >
> > And i get the error
> >
> > ImportError: No module named getopt
> >
> > Could you please point out a possible solution for this?
>
> looks like a broken installation.  try running the script as
>
> python -vv script.py
>
> and see where it looks for the getopt module.
>
> is the ImportError all you get, btw ?  it doesn't complain about site.py 
> before
> that ?
> 
> 

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


Re: ImportError: No module named getopt

2006-11-23 Thread prashant
thanks a lot that helped...


Fredrik Lundh wrote:
> "prashant" wrote:
>
> > I am actually using Cygwin to run a python script.
> > I have python 2.5 installed. But when i ran the command mentioned by
> > you... I see that it is looking in the wrong directories... how can i
> > change these look up directories?
>
> is PYTHONHOME perhaps set to the wrong thing?
>
> if not, you can point it to the root of your Python installation.  use 
> "python -h"
> for more alternatives.
> 
> 

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


insert python script in current script

2008-04-16 Thread Prashant
I was wondering is there any way to do this:

I have written a class in python and __init__ goes like this:

def __init__(self):

self.name = 'jack'
self.age = 50

import data




now here there is data.py in the same directory and contents are like:

self.address = 'your address'
self.status = 'single'

The problem is 'self' is giving some error here. I need to know if
somehow I can do this. It's like inserting the script as it's part of
the file itself.

Cheers

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


Temporary text for multiple entries

2020-08-21 Thread Prashant Aggarwal
I am working to make a form where I have added multiple entries. I wish to add 
temporary text on all of them, as the text to be deleted when clicked and to 
inserted again when focused out. I have done with the single entry but not able 
to find a solution for multiple entries.Kindly suggest me a better way to do.
-- 
https://mail.python.org/mailman/listinfo/python-list


Custom 'Float' class. Am I right here?

2008-07-16 Thread Prashant Saxena
import sys

class Float(float):
"""
Custom float datatype with addtional attributes.
"""

def __new__(self,
value=0.0, #default value
name='', # string
range=(0.0, 1.0) # tuple
)

try:
self.name = name
self.range = range
self.pos = (1, 1)
return float.__new__(self, value)
except:
print ('Invalid value : Float = %s %s' % (str(value), 
sys.exc_info()[:2]))


def setpos(self, value):
self.pos = value
def getpos(self):
return self.pos*2.0
p = property(getpos, setpos)

myFloat = Float(0.23)
print myFloat.pos

I am trying to create a custom 'float' datatype by subtyping default 'float'. 
There are few things I would like to know here:

1. How to make 'name' & 'range' only readable attributes.
2. The property 'p' is not working as it has to. What's wrong here?
3. I would be heavily instancing this class, and I won't be creating any new 
attribute on instance. Is there any way to optimize? __slots__?

Thanks



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

subtype and super method. How to?

2008-07-16 Thread Prashant Saxena
import sys

class Attribute(object):
    """
    Common attributes and methods for custom types
    """
    __slots__ = []
    
    def __init__(self, name=None, type=None, range=(0,1)):
    self.__name = name
    self.__type = type
    self.__range = range
    
    #Read only attributes
    name = property(lambda self: self.__name)
    type = property(lambda self: self.__type)
    range = property(lambda self: self.__range)
    
class Float(float, Attribute):
    '''Custom Float type'''
    __slots__ = ('__name', '__type', '__range')
    def __new__(self, value=0.0, name=None, type=None, range=(0.0, 1.0)):
    try:
    super(Float, self).__init__(name=name, type=type, range=range)
    return float.__new__(self, value)
    except:
    print 'Error : %s %s' % sys.exc_info()[:2]
    
class Int(int, Attribute):
    '''Custom Int type'''
    __slots__ = ('__name', '__type', '__range')
    def __new__(self, value=0, name=None, type=None, range=(0, 1)):
    try:
    super(Int, self).__init__(name=name, type=type, range=range)
    return int.__new__(self, value)
    except:
    print 'Error : %s %s' % sys.exc_info()[:2]

a = Float(2.0, name='myFloat')
print a

'Float' & 'Int' instances are not getting initialize. How to solve?

Thanks



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

Volunteer help with porting

2010-09-07 Thread Prashant Kumar
Hi everyone,

My name is Prashant Kumar and I wish to contribute to the Python
development process by helping convert certain existing python over to
python3k.

Is there anyway I could obtain a list of libraries which need to be
ported over to python3k, sorted by importance(by importance i mean
packages which serve as a dependency for larger number of packages
being more important).

I had originally mailed the python-dev mailing list and was pointed to
this ML so that I could get details regarding 3rd party libraries
which need to be ported.

Thanks,
Prashant Kumar
-- 
http://mail.python.org/mailman/listinfo/python-list