[web2py] Re: Threads in app

2021-01-30 Thread valq...@gmail.com
It is because pydal-db-connection is thread safe and as you switch to 
another thread there is no initialized pydal-db-connection in that thread
so you can try *db._adapter.reconnect() i*n your target function (this is 
that py4web does on every request)
And (as far as I understand) you cannot share uncommitted db-changes 
between threads as they each have their own db connection
суббота, 30 января 2021 г. в 08:58:50 UTC+3, snide...@gmail.com: 

> On Saturday, December 12, 2020 at 3:20:46 AM UTC-8 ermolaev...@gmail.com 
> wrote:
>
>> code:
>> threadGetRate = Thread(target=get_from_exch, args=(db, exchg))
>> threadGetRate.start()
>>
>> I start app by:
>>
>> > web2py.py -S 7pay_in -M -R applications/7pay_in/modules/serv_rates.py 
>> -A True 60
>>
>> rise error - for connection to DB
>>
>
>
> I'm not sure what you are trying to do here, and I don't what error you 
> are saying is happening.
>
> Can you provide more information?
>
> (typically, each request runs in its own thread, and how many threads 
> there are may depend on the front end (Rocket, NginX, Apache, unicorn, 
> etc);  The scheduler also managers a pool of threads).)
>
> /dps
>
>
>  
>

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/web2py/1d631b25-85ff-4c3f-961c-e41566431d4cn%40googlegroups.com.


[web2py] Re: Threads in app

2021-01-29 Thread Dave S

On Saturday, December 12, 2020 at 3:20:46 AM UTC-8 ermolaev...@gmail.com 
wrote:

> code:
> threadGetRate = Thread(target=get_from_exch, args=(db, exchg))
> threadGetRate.start()
>
> I start app by:
>
> > web2py.py -S 7pay_in -M -R applications/7pay_in/modules/serv_rates.py -A 
> True 60
>
> rise error - for connection to DB
>


I'm not sure what you are trying to do here, and I don't what error you are 
saying is happening.

Can you provide more information?

(typically, each request runs in its own thread, and how many threads there 
are may depend on the front end (Rocket, NginX, Apache, unicorn, etc);  The 
scheduler also managers a pool of threads).)

/dps


 

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/web2py/17446d3a-c6df-4cc7-844e-458c179271aen%40googlegroups.com.


[web2py] Re: Threads with homemade task queues

2012-05-19 Thread Massimo Di Pierro
Not all all.

A backgrund process can create processes and thread and spawn processes as 
needed. (with the limitations summarized here and discussion 
below: 
http://www.reddit.com/r/Python/comments/tpixc/ive_spent_the_past_week_tracking_down_a_bug_in/)

The restriction I taked about applies only to models, controllers and views 
and this is not a web2py specific restriction.

Massimo


On Friday, 18 May 2012 15:02:17 UTC-5, David Phillips wrote:

 I've read hearty admonishments on this forum against creating threads in 
 controller and model files, but what about the case of a background job 
 launched as a separate process – like what chapter four of the book calls 
 homemade task queues and chapter eight calls a background task? 

 My application has a long-running job that make frequent, periodic http 
 requests. After struggling with various approaches, I've finally got a 
 prototype algorithm working efficiently and correctly that makes 
 synchronous, parallel http request in a number of worker threads. I could 
 probably run my code as a separate, non-web2py python script, but it would 
 be convenient to be able to access the model.

 Do the reasons for not running creating threads inside controllers still 
 apply in the case of a separate background process?

 Thanks.

 David



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

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

[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] Re: Threads operating on database causing a crash

2011-10-16 Thread Massimo Di Pierro
P.S. What are you trying to accomplish? Web2py has a scheduler which
takes care of running background tasks in parallel.

Massimo

On Oct 16, 3:38 pm, Massimo Di Pierro massimo.dipie...@gmail.com
wrote:
 You should not start threads within actions because they are already
 running into threads created by the web sever. The web server monitors
 the threads and kills them on timeout.

 Moreover you are used the db object in the thread. That is not thread
 safe. Every thread should have its own db connection. Web2py handles
 this for you (every action runs in its own thread and has its own db)
 but you break it if you make your own threads.

 On Oct 16, 3:22 pm, Harshad hash0...@gmail.com wrote:







  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 :(


Re: [web2py] Re: Threads :-)

2011-10-10 Thread Mike Veltman

I found the solution, I was making it too complicated. Thank you for 
indirectly solving my problem.

I moved the whol stuff to the cron job and make the frontend lean and mean. So 
no need anymore for threads the frontend.

One question. when I run web2py in a cronjob can I use thread there ? Or is it 
also connected to the webserver ?

 Thanks for the response,
 
  There are two problems:
  - do not do print, breaks mod_wsgi
  - do not start threads from an action because the threads are
  controller by the web server and it may kill it.
 
 Good warnings.
 
  you should queue the task in database or cache and then run a
  background task
 
 Well actually its function is to queue tasks in redis so a cronjob can
 excute it.
 
 Well it seems I get errors while accessing the database
 
   File gluon/contrib/pymysql/connections.py, line 184, in
 defaulterrorhandler raise errorclass, errorvalue
 gluon.contrib.pymysql.err.InterfaceError: (0, '')
 
  .
  If pushing data to redis takes too long it defies the purpose of using
  redis.
 
 Well its collecting the data and combining it in redis that takes time.
 
  On Oct 9, 11:22 pm, Mike Veltman mike.velt...@gmail.com wrote:
   Ok, I need to push data in a redis database. And my problem is that it
   takes a while while the data is pushed in. So the screen would be
   waiting and a user would be irritated.
   
   My solution would be something like this.
   
   if framequeue.check_frame_lock() == False:
   if session.deployment == True:
   pass
   
   else:
   import thread
   print session.deployment
   print Running deployment
   thread.start_new_thread(default_frame_deployment,())
   
   So the thread is running in the background and the page displays the
   log.
   
   But then I get gluon (database) errors in the functions.
   
   Any idea's or is there a better/ more elegant solution to this problem
   ?
   
   With regards,
   Mike Veltman
 
 With regards,
 Mike Veltman

With regards,
Mike Veltman




[web2py] Re: Threads :-)

2011-10-10 Thread Massimo Di Pierro


On Oct 10, 2:54 am, Mike Veltman mike.velt...@gmail.com wrote:
 I found the solution, I was making it too complicated. Thank you for
 indirectly solving my problem.

 I moved the whol stuff to the cron job and make the frontend lean and mean. So
 no need anymore for threads the frontend.

 One question. when I run web2py in a cronjob can I use thread there ? Or is it
 also connected to the webserver ?

yes you can.










  Thanks for the response,

   There are two problems:
   - do not do print, breaks mod_wsgi
   - do not start threads from an action because the threads are
   controller by the web server and it may kill it.

  Good warnings.

   you should queue the task in database or cache and then run a
   background task

  Well actually its function is to queue tasks in redis so a cronjob can
  excute it.

  Well it seems I get errors while accessing the database

    File gluon/contrib/pymysql/connections.py, line 184, in
  defaulterrorhandler raise errorclass, errorvalue
  gluon.contrib.pymysql.err.InterfaceError: (0, '')

   .
   If pushing data to redis takes too long it defies the purpose of using
   redis.

  Well its collecting the data and combining it in redis that takes time.

   On Oct 9, 11:22 pm, Mike Veltman mike.velt...@gmail.com wrote:
Ok, I need to push data in a redis database. And my problem is that it
takes a while while the data is pushed in. So the screen would be
waiting and a user would be irritated.

My solution would be something like this.

if framequeue.check_frame_lock() == False:
        if session.deployment == True:
            pass

        else:
            import thread
            print session.deployment
            print Running deployment
            thread.start_new_thread(default_frame_deployment,())

So the thread is running in the background and the page displays the
log.

But then I get gluon (database) errors in the functions.

Any idea's or is there a better/ more elegant solution to this problem
?

With regards,
Mike Veltman

  With regards,
  Mike Veltman

 With regards,
 Mike Veltman


Re: [web2py] Re: Threads :-)

2011-10-10 Thread Jonathan Lundell
On Oct 10, 2011, at 6:51 AM, Massimo Di Pierro wrote:

 On Oct 10, 2:54 am, Mike Veltman mike.velt...@gmail.com wrote:
 I found the solution, I was making it too complicated. Thank you for
 indirectly solving my problem.
 
 I moved the whol stuff to the cron job and make the frontend lean and mean. 
 So
 no need anymore for threads the frontend.
 
 One question. when I run web2py in a cronjob can I use thread there ? Or is 
 it
 also connected to the webserver ?
 
 yes you can.

Except for softcron, presumably?

[web2py] Re: Threads :-)

2011-10-10 Thread Massimo Di Pierro
oops. true.

On Oct 10, 9:30 am, Jonathan Lundell jlund...@pobox.com wrote:
 On Oct 10, 2011, at 6:51 AM, Massimo Di Pierro wrote:

  On Oct 10, 2:54 am, Mike Veltman mike.velt...@gmail.com wrote:
  I found the solution, I was making it too complicated. Thank you for
  indirectly solving my problem.

  I moved the whol stuff to the cron job and make the frontend lean and 
  mean. So
  no need anymore for threads the frontend.

  One question. when I run web2py in a cronjob can I use thread there ? Or 
  is it
  also connected to the webserver ?

  yes you can.

 Except for softcron, presumably?


[web2py] Re: Threads :-)

2011-10-09 Thread mdipierro
There are two problems:
- do not do print, breaks mod_wsgi
- do not start threads from an action because the threads are
controller by the web server and it may kill it.

you should queue the task in database or cache and then run a
background task.
If pushing data to redis takes too long it defies the purpose of using
redis.

On Oct 9, 11:22 pm, Mike Veltman mike.velt...@gmail.com wrote:
 Ok, I need to push data in a redis database. And my problem is that it takes a
 while while the data is pushed in. So the screen would be waiting and a user
 would be irritated.

 My solution would be something like this.

 if framequeue.check_frame_lock() == False:
         if session.deployment == True:
             pass
         else:
             import thread
             print session.deployment
             print Running deployment
             thread.start_new_thread(default_frame_deployment,())

 So the thread is running in the background and the page displays the log.

 But then I get gluon (database) errors in the functions.

 Any idea's or is there a better/ more elegant solution to this problem ?

 With regards,
 Mike Veltman


Re: [web2py] Re: Threads :-)

2011-10-09 Thread Mike Veltman
Thanks for the response,

 There are two problems:
 - do not do print, breaks mod_wsgi
 - do not start threads from an action because the threads are
 controller by the web server and it may kill it.
 

Good warnings. 

 you should queue the task in database or cache and then run a
 background task

Well actually its function is to queue tasks in redis so a cronjob can excute 
it. 

Well it seems I get errors while accessing the database

  File gluon/contrib/pymysql/connections.py, line 184, in defaulterrorhandler
raise errorclass, errorvalue
gluon.contrib.pymysql.err.InterfaceError: (0, '')


 .
 If pushing data to redis takes too long it defies the purpose of using
 redis.

Well its collecting the data and combining it in redis that takes time.

 
 On Oct 9, 11:22 pm, Mike Veltman mike.velt...@gmail.com wrote:
  Ok, I need to push data in a redis database. And my problem is that it
  takes a while while the data is pushed in. So the screen would be
  waiting and a user would be irritated.
  
  My solution would be something like this.
  
  if framequeue.check_frame_lock() == False:
  if session.deployment == True:
  pass
  else:
  import thread
  print session.deployment
  print Running deployment
  thread.start_new_thread(default_frame_deployment,())
  
  So the thread is running in the background and the page displays the log.
  
  But then I get gluon (database) errors in the functions.
  
  Any idea's or is there a better/ more elegant solution to this problem ?
  
  With regards,
  Mike Veltman

With regards,
Mike Veltman