Ahhh, I got it now - Thanks so much Simon! The problem was I had left out close_fds, so it was still spawning as a child process I think. With close_fds it works a treat - thank you once again :D
- Ollie On Jul 5, 3:18 pm, Simon Drabble <[EMAIL PROTECTED]> wrote: > On Thu, 5 Jul 2007, Oliver Charles wrote: > > > That doesn't work, I've tried that, it still hangs the view. > > > Give it a shot with a long python script (while True: time.sleep(1) > > would do) and you'll find that the view never returns. If you can get > > it to return, I'd love to see your code, but it's no go for me... > > Well, modulo the script name & arguments, that's the code I'm using > successfully to run background processes. How have you verified that > the view does not return? Does the sub-process actually start (i.e. > can you see it with ps)? What OS are you using, and have you verified > that the code you are uring works outside of django (write a small > shell script that does nothing but call the external torrent process - > does that work as expected?). > > -Simon. > > > > > On Jul 5, 2:57 pm, Simon Drabble <[EMAIL PROTECTED]> wrote: > >> On Thu, 5 Jul 2007, Oliver Charles wrote: > > >>> Just to give an update, I've tried forking the view, and then turning > >>> the child process into a daemon with a double fork, and then exiting > >>> before it gets to the return, and letting the parent do the return, > >>> but this is not working either... > > >>> I'm stumped, and don't really want to have to create a specific > >>> controller daemon (but guess I'm going to have to) > > >>> - Olllie > > >> Use the subprocess module: > > >> import subprocess > >> ... > >> script = 'python' > >> args = (script, '/path/to/executable', ...) > >> env = { ... } > >> pid = subprocess.Popen(args, close_fds=True, env=env).pid > > >> t = Torrent.objects.create(pid=pid) > >> ... > > >> Remember to store the pid for later wait()ing or you'll end up with > >> zombies. > > >> -Simon. > > >>> On Jul 5, 2:58 am, Oliver Charles <[EMAIL PROTECTED]> wrote: > >>>> Hi > > >>>> I'm currently playing around trying to make something akin to > >>>> TorrentFlux, using Django. TorrentFlux is a system that's PHP and it > >>>> calls shell scripts to download torrents in the background, with a web > >>>> interface to control them. For every torrent download, a new process > >>>> is started, which runs with the torrent - downloading and seeding it. > > >>>> My system is similar, and i'm at a very proof of concept stage at the > >>>> moment. However, I've hit a problem. I can't find a nice way to spawn > >>>> the processes, without Django hanging as long as the process needs > >>>> (and for 600mb torrents, that's gonna be hours, and endless if seeding > >>>> is expected). > > >>>> At the moment I am doing: > > >>>> def start(request): > > >>>> p = os.spawnlp(os.P_NOWAIT, 'python', 'python', '/Users/acid/Work/ > >>>> dTorrent/btdownloadheadless', > >>>> '/Users/acid/Desktop/Inbox/-{mininova.org}- Professional C+ > >>>> +.torrent') > > >>>> t = Torrent.objects.create(pid=p) > > >>>> return HttpResponse(str(p)) > > >>>> But this is hanging, despite the P_NOWAIT (the Torrent model does get > >>>> created). > > >>>> Any ideas? > > >> -- > > -- --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---