[web2py] Cannot access db in a thread

2016-12-02 Thread Harshad
I have a separate process that I run along with my web application by 
creating a subprocess like so:

   subprocess.Popen("python web2py.py -v -e -a admin -i 0.0.0.0 -p 
8080 -c  -k ".split())
subprocess.Popen("python web2py.py -S  -M -R 
".split())

In that process, I start a thread to do some tasks. I have assigned the 
callbacks from that thread to the callbacks in that process:

Class Process:

def __init__(self):
self.thread = MyThread() #MyThread is a threading.Thread object
self.thread.callback = self.callback
self.thread.start()

def self.callback(self, event):
print db(auth_user.id=1).first_name

In the self.callback, when I try to read from the database using the db 
object I get the following error:

AttributeError: 'thread._local' object has no attribute 
'_pydal_connection_55197392_9964'

I have tried making the db object a member of the Process class and then 
trying to access it in the callback:

Class Process:

def __init__(self):
self.db = db
self.thread = Threading.thread()
self.thread.callback = self.callback
self.thread.start()

def self.callback(self, event):
print self.db(auth_user.id=1).first_name

I still get the same error.

How can I access the database from inside a thread created inside a process 
running in a shell?

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] Hardware Requirements for Deployment

2011-11-02 Thread Harshad
I've been asked by my colleagues to enumerate all hardware requirements for 
deploying a server running web2py. My question is, how do I even begin to 
calculate the requirements for the architecture, storage space, memory, 
etc.? For architecture, am I basically stuck with x86? For storage, is the 
only consideration going to be the database? For memory, do I basically run 
the server with users and profile the memory usage?

Re: [web2py] AJAX weirdness

2011-10-19 Thread Harshad
Thanks to rochacbruno and Anthony, I was able to solve this problem. All I 
did was include the line response.generic_patters=[*] in db.py.

Re: [web2py] AJAX weirdness

2011-10-19 Thread Harshad
Before we close this thead, I am curious as to why/how is this a security 
risk?

Re: [web2py] AJAX weirdness

2011-10-19 Thread Harshad
Makes sense. Thanks.

[web2py] Re: AJAX weirdness

2011-10-18 Thread Harshad
$.ajax({
type: GET,
url: 
'http://Harshad-PC.local/devicemanager/default/get_response.json/192.168.1.24/107',
success: function(data,textStatus,jqXHR) {alert(Success! Data: 
+data)},
error: function(data,textStatus,jqXHR) {alert(Error: Failed to load 
data.)}
});

Tried that, still the same.


[web2py] Re: AJAX weirdness

2011-10-18 Thread Harshad
Wouldn't this only be a problem if I was actually making a cross-domain 
call? The remote machines are on the same local area network as the server.

Re: [web2py] AJAX weirdness

2011-10-18 Thread Harshad
I'm at home right now, but I'll try that at work tomorrow.

Thanks.


[web2py] Re: Threads operating on database causing a crash

2011-10-17 Thread Harshad
Seriously, no one?

[web2py] Re: Design Issue

2011-10-17 Thread Harshad
Oh, I see your point. Letting the main thread do all the db interaction 
makes perfect sense. Also, I'll use the queue model for interaction between 
the main thread and the send/receive threads.

Thanks Massimo - you're a good man.


[web2py] Re: Threads operating on database causing a crash

2011-10-17 Thread Harshad
*Update:* Issue has been addressed in the following thread
 
https://groups.google.com/forum/#!topic/web2py/R8N2CRP-ifYhttps://groups.google.com/forum/#!topic/web2py/R8N2CRP-ifY

[web2py] Threads operating on database causing a crash

2011-10-16 Thread Harshad
class Worker(threading.Thread):
def run(self):
print self.name, running...
while True:
if db(db.temperature).isempty():
print empty
else:
print not empty
time.sleep(1)

Running the above code causes the application to seg fault. Any ideas?


[web2py] Re: Threads operating on database causing a crash

2011-10-16 Thread Harshad
The design is discussed 
here: https://groups.google.com/forum/#!topic/web2py/R8N2CRP-ifY

I was hoping to get some feedback on that but never got any :(


[web2py] Design Issue

2011-10-14 Thread Harshad
I am trying to create a web app that allows you to control various devices 
simultaneously. The simplified design is as follows:

   - One main background process continuously polls a database table for any 
   device control requests
  - Once it sees a request, it spawns two threads: send and receive 
  thread
   - Send thread periodically polls the commands table
   - Receive thread updates the responses table
   - The view basically writes to the commands table and polls the responses 
   table 

First of all, is this a good design? Should the communication between the 
threads and the view be through the database (SQLite)? Also, its worth 
mentioning that there the database is updated quite often since the device 
is being controlled in real-time.


[web2py] JSONP in web2py

2011-10-12 Thread Harshad
I know this has been discussed earlier, but I am not sure how to use
JSONP for cross domain communication correctly. This is how I make the
request:

var jqxhr = $.getJSON('get_devices.jsonp', function(data) {
displayList(data);
})
.error(function() { alert(error); })

I have tried the following URLs:

1. get_devices.json (works on local, fails on remote)
2. get_devices.jsonp (fails on local and remote)
3. get_devices.jsonp?callback=? (works on local, fails on remote)

And my controller simply does the following:

def get_devices():
devices = []
rows=db().select(db.device_status.hostname)
for eachrow in rows:
devices.append(eachrow.hostname)
return dict(devices=devices)



[web2py] Sharing a database between apps

2011-10-07 Thread Harshad
I was wondering if its possible to share a database between apps. I
have two apps. One is a background process that discovers devices on
the network using bonjour and adds them to the database. The other app
provides a web interface to view these discovered devices.

How do I share the same database? Do I define the table twice?


[web2py] Re: Sharing a database between apps

2011-10-07 Thread Harshad
Nice. So all I have to do is define them in every application that is
using them and set migrate=False.

And, next time I'll try to RTFM more carefully.

Thanks Cliff!

On Oct 7, 12:19 pm, Cliff cjk...@gmail.com wrote:
 Yes.

 More information is available here:  
 http://web2py.com/book/default/chapter/04#Cooperation

 On Oct 7, 11:11 am, Harshad hash0...@gmail.com wrote:







  I was wondering if its possible to share a database between apps. I
  have two apps. One is a background process that discovers devices on
  the network using bonjour and adds them to the database. The other app
  provides a web interface to view these discovered devices.

  How do I share the same database? Do I define the table twice?