omz:forum

    • Register
    • Login
    • Search
    • Recent
    • Popular

    Welcome!

    This is the community forum for my apps Pythonista and Editorial.

    For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.


    Permission error with multiprocessing.Process

    Pythonista
    multiprocessing processes process errno 1
    3
    11
    7867
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • max
      max last edited by max

      I was testing the multiprocessing module and I ran this script on PC and it works fine, but using Pythonista on IOS gives PermissionError: [Errno 1] Operation not permitted. Anyone know how to fix this?

      from multiprocessing import Process
      
      def f(name):
          print('hello', name)
      
      if __name__ == '__main__':
          p = Process(target=f, args=('bob'))
          p.start()
          p.join()
      
      1 Reply Last reply Reply Quote 0
      • JonB
        JonB last edited by

        multiprocessing is not supported on ios.

        1 Reply Last reply Reply Quote 2
        • zrzka
          zrzka last edited by

          It's b/o Apple, not b/o Pythonista. Only one process is allowed until Apple relaxes (if ever) this rule.

          max 1 Reply Last reply Reply Quote 2
          • max
            max @zrzka last edited by

            @zrzka thanks. Do you know of any alternatives that would be supported? I’ve tried threading but it doesn’t do exactly what I need

            1 Reply Last reply Reply Quote 0
            • zrzka
              zrzka last edited by

              And what exactly is what I need? No crystal ball here ;)

              max 1 Reply Last reply Reply Quote 0
              • max
                max @zrzka last edited by

                @zrzka sorry for being vague. I need to run a function multiple times in parallel pretty much

                1 Reply Last reply Reply Quote 0
                • zrzka
                  zrzka last edited by zrzka

                  What kind of function, I mean, what it does? I/O like networking, computational, ...?

                  Update: Can you elaborate more on what do you want to achieve?

                  max 1 Reply Last reply Reply Quote 0
                  • max
                    max @zrzka last edited by

                    @zrzka yeah. Basically it’s a program that fills and submits out a number of online forms using requests. And i’d Like to run it multiple times in parallel so it can fill multiple forms at a time.

                    1 Reply Last reply Reply Quote 0
                    • JonB
                      JonB last edited by JonB

                      Okay, so, Spambot :).

                      Though you cannot use multiprocessing, you can use asyncio /aiohttp and the like.

                      There are a few wrappers for requests
                      https://github.com/rdbhost/yieldfromRequests
                      Or
                      https://github.com/jsandovalc/aiorequests
                      Which allow use of asyncio and requests. I have not tried it on pythonista, but many examples of code that use aiohttp show huge increases in number of requests per second. Happy spamming...

                      max 1 Reply Last reply Reply Quote 0
                      • max
                        max @JonB last edited by

                        @JonB thank you! I’m pretty new to python and coding in general so I appreciate your help

                        1 Reply Last reply Reply Quote 0
                        • zrzka
                          zrzka last edited by

                          I personally do use aiohttp, sanic, asyncio, aiomysql, ... and I really enjoy it. It's a huge difference in performance. Was doing some benchmarks for my Slack Applications / bots and the difference was noticeable, even by the end users. (Mostly prototypes / MVPs, reason for experimenting with sanic).

                          Anyway, here's an example. You can learn how to fire & wait for one request and how to fire & wait for many of them.

                          NOTE: No error handling & coindesk has rate limiting. Run this two, three times and then you have to wait.

                          import asyncio
                          import aiohttp
                          
                          
                          async def get_currencies(session):
                              async with session.get('https://api.coindesk.com/v1/bpi/supported-currencies.json') as response:
                                  result = await response.json(content_type='text/html')
                                  return {x['currency']: x['country'] for x in result}
                          
                          
                          async def bitcoin_price(session, currency):
                              async with session.get(f'https://api.coindesk.com/v1/bpi/currentprice/{currency}.json') as response:
                                  result = await response.json(content_type='application/javascript')
                                  return result['bpi'][currency]
                          
                          
                          async def bitcoin_prices():
                              async with aiohttp.ClientSession() as session:
                                  # Get list of available currencies
                                  currencies = await get_currencies(session)
                                  
                                  # Prepare tasks for all currencies
                                  tasks = [
                                      asyncio.ensure_future(bitcoin_price(session, currency))
                                      for currency in currencies.keys()
                                  ]
                                  
                                  # Fire them and wait for results
                                  await asyncio.gather(*tasks)
                                  results = [x.result() for x in tasks]
                                  
                                  # Print them
                                  for x in results:
                                      print(' - {0} {1:12.1f} {2}'.format(x['code'], x['rate_float'], x['description']))
                                  
                              
                          def main():
                              loop = asyncio.get_event_loop()
                              loop.run_until_complete(bitcoin_prices())
                              
                                  
                          if __name__ == '__main__':
                              main()
                          
                          1 Reply Last reply Reply Quote 0
                          • First post
                            Last post
                          Powered by NodeBB Forums | Contributors