Threads with homemade task queues

43 views
Skip to first unread message

David Phillips

unread,
May 18, 2012, 4:02:17 PM5/18/12
to web...@googlegroups.com
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

Massimo Di Pierro

unread,
May 19, 2012, 3:41:06 PM5/19/12
to web...@googlegroups.com
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
Reply all
Reply to author
Forward
0 new messages