Hey,
I'm running a function which evaluates commands passed in using stdin and another function which runs a bunch of jobs. I need to make the latter function sleep at regular intervals but that seems to be blocking the stdin. Any advice on how to resolve this would be appreciated.
The source code for the functions is
def runJobs(comps, jobQueue, numRunning, limit, lock):
while len(jobQueue) >= 0:
print(len(jobQueue));
if len(jobQueue) > 0:
comp, tasks = find_computer(comps, 0);
#do something
time.sleep(5);
def manageStdin():
print "Global Stdin Begins Now"
for line in fileinput.input():
try:
print(eval(line));
except Exception, e:
print e;
--Thanks
Hi,
I am new to numpy. Am wonder is there a way to do lookup of two ndarray of different shapes?
for example, i have 2 ndarrays as below:
X = array([[0, 3, 6],
[3, 3, 3],
[6, 0, 3]])
Y = array([[0, 100],
[3, 500],
[6, 800]])
and would like to lookup each element of X in Y, then be able to return the second column of Y:
Z = array([[100, 500, 800],
[500, 500, 500],
[800, 100, 500]])
thanks, fahhean
I want to have a twisted service (started via twistd) which listens to TCP/POST request on a specified port on a specified IP address. By now I have a twisted application which listens to port 8040 on localhost. It is running fine, but I want it to only listen to a certain IP address, say 10.0.0.78.
How-to manage that? This is a snippet of my code:
application = service.Application('SMS_Inbound')
smsInbound = resource.Resource()
smsInbound.putChild('75sms_inbound',ReceiveSMS(application))
smsInboundServer = internet.TCPServer(8001, webserver.Site(smsInbound))
smsInboundServer.setName("SMS Handling")
smsInboundServer.setServiceParent(application)
i have a directory with around 1000 files....i want to run a same code for each of these file...
my code requires the file name to be inputted.
i have written code to copy the information of one into other in other format...
please suggest a method to copy all 1000 files one by one without need to change the file name every time
and i have a field serial_num which need to be continous i.e if 1st file has upto 30 then while coping other file it should continue from 30not from 0 again
require suggestion please
thanks..
Hello,
I have 3 panels and I want to make drags on them.
The problem is that when I do a drag on one this happens:
How can I refresh the frame to happear its color when the panel is no longer there?
I have a folder full of files and i want to search some string inside them. The issue is that some files may be zip,exe,ogg,etc.
Can i check somehow what kind of file is it so i only open and search through txt, php, etc files.
I can't rely on the file extension.
MYMESSAGE = "<div>Hello</div><p></p>Hello"
send_mail("testing",MYMESSAGE,"[email protected]",['[email protected]'],fail_silently=False)
However, this message doesn't get the HTML mime type when it is sent. In my outlook, I see the code...
I'm working on a PyGTK app with some Buttons that, when clicked, give a text entry dialog, then set the text on the button to whatever was entered in the box. The problem is that if the text is longer than the button can show, the button changes size to accomodate. How do I keep GTK Buttons from resizing when the text changes?
i want to find a webapp framework for validation user , store user,
and has ajax Effect of jquery ,
so ,did you know this simply framework ?
thanks
like this page : http: //digu.com/reg
We've had some good experiences building an app on Google App Engine, this first app's target audience are Google Apps users, so no issues there in terms of it being hosted on Google infrastructure.
We like it so much that we would like to investigate using it for a another app, however this next project is for a client who is not really that interested in what technology it sits on, they just want it to work, and work all of the time.
In this scenario, given that we have the technology applicability and capability side covered, are there any concerns that this stuff is still relatively new and that we may not be as much "in control" as if we had it done with traditional hosting?
Hi everyone.
This question is in continuation to my previous question, in which I asked about passing around an ElementTree.
I need to read the XML files only and to solve this, I decided to create a global ElementTree and then parse it wherever required.
My question is:
Is this an acceptable practice? I heard global variables are bad. If I don't make it global, I was suggested to make a class. But do I really need to create a class? What benefits would I have from that approach. Note that I would be handling only one ElementTree instance per run, the operations are read-only. If I don't use a class, how and where do I declare that ElementTree so that it available globally? (Note that I would be importing this module)
Please answer this question in the respect that I am a beginner to development, and at this stage I can't figure out whether to use a class or just go with the functional style programming approach.
Hi all,
I find I've been confused by the problem that when I needn't to use try..except.For last few days it was used in almost every function I defined which I think maybe a bad practice.For example:
class mongodb(object):
def getRecords(self,tname,conditions=''):
try:
col = eval("self.db.%s" %tname)
recs = col.find(condition)
return recs
except Exception,e:
#here make some error log with e.message
What I thought is ,exceptions may be raised everywhere and I have to use try to get them.
And my question is,is it a good practice to use it everywhere when defining functions?If not are there any principles for it?Help would be appreciated!
Regards
I use ZODB and i want to copy my 'database_1.fs' file to another 'database_2.fs',
so I opened the root dictionary of that 'database_1.fs' and I (pickle.dump) it in a text file.
Then I (pickle.load) it in a dictionary-variable, in the end I update the root dictionary of the other 'database_2.fs' with the dictionary-variable.
It works, but I wonder why the size of the 'database_1.fs' not equal to the size of the other 'database_2.fs'.
They are still copies of each other.
def openstorage(store): #opens the database
data={}
data['file']=filestorage
data['db']=DB(data['file'])
data['conn']=data['db'].open()
data['root']=data['conn'].root()
return data
def getroot(dicty):
return dicty['root']
def closestorage(dicty): #close the database after Saving
transaction.commit()
dicty['file'].close()
dicty['db'].close()
dicty['conn'].close()
transaction.get().abort()
then that's what i do:-
import pickle
loc1='G:\\database_1.fs'
op1=openstorage(loc1)
root1=getroot(op1)
loc2='G:database_2.fs'
op2=openstorage(loc2)
root2=getroot(op2)
>>> len(root1)
215
>>> len(root2)
0
pickle.dump( root1, open( "save.txt", "wb" ))
item=pickle.load( open( "save.txt", "rb" ) ) #now item is a dictionary
root2.update(item)
closestorage(op1)
closestorage(op2)
#after I open both of the databases
#I get the same keys in both databases
#But `database_2.fs` is smaller that `database_2.fs` in size I mean.
>>> len(root2)==len(root1)==215 #they have the same keys
True
Note:
(1) there are persistent dictionaries and lists in the original database_1.fs
(2) both of them have the same length and the same indexes.
I have a table, Foo. I run a query on Foo to get the ids from a subset of Foo. I then want to run a more complicated set of queries, but only on those IDs. Is there an efficient way to do this? The best I can think of is creating a query such as:
SELECT ... --complicated stuff
WHERE ... --more stuff
AND id IN (1, 2, 3, 9, 413, 4324, ..., 939393)
That is, I construct a huge "IN" clause. Is this efficient? Is there a more efficient way of doing this, or is the only way to JOIN with the inital query that gets the IDs? If it helps, I'm using SQLObject to connect to a PostgreSQL database, and I have access to the cursor that executed the query to get all the IDs.
I have around 20 functions (is_func1, is_fucn2, is_func3...) returning boolean
I assume there is only one function which returns true and I want that!
I am doing:
if is_func1(param1, param2):
# I pass 1 to following
abc(1) # I pass 1
some_list.append(1)
elif is_func2(param1, param2):
# I pass 2 to following
abc(2) # I pass 1
some_list.append(2)
...
.
.
elif is_func20(param1, param2):
...
Please note: param1 and param2 are different for each, abc and some_list take parameters depending on the function.
The code looks big and there is repetition in calling abc and some_list, I can pull this login in a function! but is there any other cleaner solution?
I can think of putting functions in a data structure and loop to call them.
Hello to all!
I am writing a small Django application and I should be able to create
for each model object its periodical task which will be executed with
a certain interval. I'm use for this a Celery application, but i can't understand one thing:
class ProcessQueryTask(PeriodicTask):
run_every = timedelta(minutes=1)
def run(self, query_task_pk, **kwargs):
logging.info('Process celery task for QueryTask %d' %
query_task_pk)
task = QueryTask.objects.get(pk=query_task_pk)
task.exec_task()
return True
Then i'm do following:
>>> from tasks.tasks import ProcessQueryTask
>>> result1 = ProcessQueryTask.delay(query_task_pk=1)
>>> result2 = ProcessQueryTask.delay(query_task_pk=2)
First call is success, but other periodical calls returning the error
- TypeError: run() takes exactly 2 non-keyword arguments (1 given) in
celeryd server.
So, can i pass own params to PeriodicTask run() ?
Thanks!
My test code is as follows, using threading, count is not 5,000,000 , so there has been data race, but using gevent, count is 5,000,000, there was no data race .
Is not gevent coroutine execution will atom "count + = 1", rather than split into a one CPU instruction to execute?
# -*- coding: utf-8 -*-
import threading
use_gevent = True
use_debug = False
cycles_count = 100*10000
if use_gevent:
from gevent import monkey
monkey.patch_thread()
count = 0
class Counter(threading.Thread):
def __init__(self, name):
self.thread_name = name
super(Counter, self).__init__(name=name)
def run(self):
global count
for i in xrange(cycles_count):
if use_debug:
print '%s:%s' % (self.thread_name, count)
count = count + 1
counters = [Counter('thread:%s' % i) for i in range(5)]
for counter in counters:
counter.start()
for counter in counters:
counter.join()
print 'count=%s' % count
I'm running SQLAlchemy on Jython and trying to connect to a MS SQL database using jTDS with windows authentication. I can query and delete just fine but when I try to insert new values it will hang when I commit.
int 'before add'
session.add(newVal)
print 'after add'
session.commit()
print 'after commit'
I see the first two print statements but not the last. My CPU maxes out and I can't even query the table directly using the MS SQL Management Studio. When I kill the Jython java process I can query again but the new values haven't been added.
Strangely enough I can insert values directly using an SQL command:
insert_sql = "INSERT INTO my_table (my_value) VALUES ('test_value')"
session.execute(insert_sql)
session.commit()
Any ideas what I'm doing wrong?
The title says it all. The objective is to have two simple ways to source some code, say func.R, containing a function. Calling R CMD BATCH func.R initializes the function and evaluates is. Within a session, issuing source("func.R") simply initializes the function.
Any idea?
I have the following models in my Django app. How can I from the Team model find all the User objects who have accepted as True in the Membership model? I know I need to use Team.objects.filter(), but I'm not sure how to check the value of the accepted field.
from django.contrib.auth.models import User
class Team(models.Model):
members = models.ManyToManyField(User, through="Membership")
class Membership(models.Model):
user = models.ForeignKey(User)
team = models.ForeignKey(Team)
accepted = models.BooleanField(default=False)
I have two wxListCtrl and want to process the Ctrl+Enter keyboard event without letting wx change the focus to the other ListCtrl.
I have event handlers for wx.EVT_KEY_DOWN, wx.EVT_KEY_UP, wx.EVT_CHAR and KillFocus, but KillFocus is always called first, then the focus changes and the the keyboard handlers are called for the wrong ListCtrl.
Is there a way to prevent wx from changing the focus, when Ctrl+Enter is pressed ?