Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #77785
| Path | csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!eternal-september.org!feeder.eternal-september.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed2a.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <travisgriggs@gmail.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.003 |
| X-Spam-Evidence | '*H*': 0.99; '*S*': 0.00; 'essentially': 0.04; 'root': 0.05; 'python3': 0.07; '"__main__":': 0.09; '#print': 0.09; '__name__': 0.09; 'failed:': 0.09; 'main()': 0.09; 'try:': 0.09; 'def': 0.12; 'creates': 0.14; 'thread': 0.14; 'times,': 0.14; "'__main__':": 0.16; '(%s)"': 0.16; 'fork': 0.16; 'main():': 0.16; 'packets.': 0.16; 'subject:under': 0.16; 'sys.exit(0)': 0.16; 'sys.exit(1)': 0.16; 'threads,': 0.16; 'travis': 0.16; 'subject:python': 0.16; 'wrote:': 0.18; 'trying': 0.19; 'basically': 0.19; 'thu,': 0.19; '>>>': 0.22; 'memory': 0.22; 'import': 0.22; 'print': 0.22; 'looks': 0.24; 'this:': 0.26; 'second': 0.26; 'header:In-Reply-To:1': 0.27; 'chris': 0.29; 'am,': 0.29; 'reporting': 0.29; 'code': 0.31; 'that.': 0.31; '-0700,': 0.31; 'layer': 0.31; 'sep': 0.31; 'probably': 0.32; 'running': 0.33; 'skip:# 10': 0.33; 'skip:t 40': 0.33; 'problem': 0.35; 'board': 0.35; 'created': 0.35; 'except': 0.35; 'something': 0.35; 'received:google.com': 0.35; 'executing': 0.36; 'skip:> 10': 0.36; 'subject:service': 0.36; 'subject:?': 0.36; 'two': 0.37; 'message-id:@gmail.com': 0.38; 'depends': 0.38; 'mine': 0.38; 'process,': 0.38; 'to:addr:python-list': 0.38; 'pm,': 0.38; 'does': 0.39; 'to:addr:python.org': 0.39; 'skip:t 30': 0.61; 'simple': 0.61; 'complete': 0.62; 'address': 0.63; 'header :Message-Id:1': 0.63; 'show': 0.63; 'networking': 0.64; 'different': 0.65; 'charset:windows-1252': 0.65; 'between': 0.67; 'periodically': 0.68; 'serial': 0.72; 'day': 0.76; 'discover': 0.82; '2014,': 0.84; 'it\x92s': 0.84; 'transactions': 0.91 |
| DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=content-type:mime-version:subject:from:in-reply-to:date :content-transfer-encoding:message-id:references:to; bh=SeWT9YIznlLAVGAIMiEVfAS4bYdxhe1gh/Gg1cJv+Ms=; b=N9fhqw2gapBfT9cxSMoOS2Rarmwpdjg5pOr+SrkucsnocLP/9ZO14zfUd9oAoJ/AgG lKbnrBda3Gs4nTFzmvzW6yGO3tp1Kgx1LxA97VuiobmubbaSmtyvFgawbW+9HsZeuEw2 wb3busRJVrhnv05SGLlS+4qadgLr1MBtjjQn4SganlyYPR0z8V9mqMePPF1oB9x07iFw Ptzmd2Zd9ZgHarxbXaXEZz4Yr3us84JQuquzMPEdM9IJhsoqGweWCnP/sFEse2NfaklV jpZGxyeos7ZuoNgFu3aZcJBavna//g/DRwJJz0/n6wDN9seK4+AdGFVukzOmkBpfwtBo IUfQ== |
| X-Received | by 10.66.192.40 with SMTP id hd8mr5906742pac.123.1410479159106; Thu, 11 Sep 2014 16:45:59 -0700 (PDT) |
| Content-Type | text/plain; charset=windows-1252 |
| Mime-Version | 1.0 (Mac OS X Mail 7.3 \(1878.6\)) |
| Subject | Re: Example of python service running under systemd? |
| From | Travis Griggs <travisgriggs@gmail.com> |
| In-Reply-To | <20140911212921.GB26465@arxnet.hu> |
| Date | Thu, 11 Sep 2014 16:45:56 -0700 |
| Content-Transfer-Encoding | quoted-printable |
| References | <FE4C3550-8958-4F72-8AFE-62AA7248D6AF@gmail.com> <CAMw+j7+LQL_+77ejCFVSqWap7Rk9gS_Wu5d3y0gT1UpB8hiZAA@mail.gmail.com> <6B97B7A5-0816-401E-9BDD-A23FFC646985@gmail.com> <20140911212921.GB26465@arxnet.hu> |
| To | python-list@python.org |
| X-Mailer | Apple Mail (2.1878.6) |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.15 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list/> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.13949.1410479578.18130.python-list@python.org> (permalink) |
| Lines | 82 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1410479578 news.xs4all.nl 2922 [2001:888:2000:d::a6]:42315 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:77785 |
Show key headers only | View raw
On Sep 11, 2014, at 2:29 PM, Ervin Hegedüs <airween@gmail.com> wrote:
> Hi Travis,
>
> On Thu, Sep 11, 2014 at 02:06:48PM -0700, Travis Griggs wrote:
>>
>> On Sep 11, 2014, at 11:18 AM, Chris “Kwpolska” Warrick <kwpolska@gmail.com> wrote:
>>
>>> Depends what you want.
>>
>> Mine is not a web service. My main.py looks like this:
>>
>> #!/usr/bin/env python3
>>
>> import cycle
>> import pushTelemetry
>> from threading import Thread
>>
>> def main():
>> Thread(target=pushTelemetry.udpLoop).start()
>> Thread(target=cycle.cycleLoop).start()
>>
>> if __name__ == '__main__':
>> main()
>>
>> It basically creates two threads, one which does some local processing and control, the other which periodically does reporting via udp packets. I use the dual threads because they both work with a shared serial port at times, so I have to synchronize access through that.
>>
>> What I want is to have this startup, after my board has it’s networking layer up and running (and hopefully a valid ip address by then), and to just keep running forever
>
> may be you think about the fork(), eg:
>
> if __name__ == "__main__":
> ...other codes, eg. drop root privileges, ...
> ...check arguments...
> try:
> pid = os.fork()
> if pid > 0:
> #print "Daemon started (pid: %d)" % (pid)
> sys.exit(0)
> except OSError, e:
> print >>sys.stderr, "fork #1 failed: %d (%s)" % (e.errno, e.strerror)
> sys.exit(1)
>
> os.chdir("/")
> os.setsid()
> os.umask(0)
>
> # do second fork
> try:
> pid = os.fork()
> if pid > 0:
> #print "Daemon started (pid: %d)" % (pid)
> sys.exit(0)
> except OSError, e:
> print >>sys.stderr, "fork #2 failed: %d (%s)" % (e.errno, e.strerror)
> sys.exit(1)
>
> main()
OK, I’m probably going to show my naivety about something simple here…
I thought a “fork” essentially created a memory copy of the original process and let it go off running. The problem is, in the bowels of the code executing in those loops, I access a single instance of a threading.RLock, so that I can avoid both threads trying to do transactions with a single serial port at the same time. If I end up with two copies of the base process, unhooked from their parent, does that RLock still remain valid between the two? I thought since they were complete different copies of the same memory, they would no longer be coordinated.
Is this a day where I discover something new?
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: Example of python service running under systemd? Travis Griggs <travisgriggs@gmail.com> - 2014-09-11 16:45 -0700
csiph-web