Python R/W to text file network [closed] - python

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 9 years ago.
Improve this question
What could happen if multiple users run the same copies of python script which designed to R/W data to a single text file store in network device at the same time?
Will the processes stop working?
If so, what could be the solution?

It can happen many bad things, I don't think the processes stop working, not at least because of concurrent access to file a file, but what could happen is and inconsistent file creation: for example, if one processes write hello, and there is a concurrent access to the file, you might get a line like hhelllolo
A solution I can see is, use a database as suggested, or, create a mechanism for locking the file to concurrent accesses (which might be cumbersome because you're working on network, not the same computer)
Another solution I can think of is create a server side simple script who handle the requests and lock the file for concurrent access. This is almost the same solution as using a database, you'll be creating an storage system from scratch so why bother :)
Hope this helps!

Related

Could you check it's possible (Selenium python automation + PHP) [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
Our system is developed with PHP and one of our coworkers developed Amazon automation program with Python.
I am wondering if it's possible to integrate together ?
if it is please recommend what ways i can do this
https://github.com/jasonminsookim/order_automation/blob/master/src/amzn.py
Here's code Amazon automation program
Thank you
There are lots of ways to do this, but I would weigh what you have available to you and go from there. The tempfile solution is the most general, and is a common interface pattern for any two or more languages, but you can get more exotic if performance is a major concern with pipes.
Temp-file
I guess the most rudimentary way to do this would be to have the python file output some data to a file that can be read in by php or vice versa.
Something like creating a directory called /orders where php put's in order.json files and python takes those in, reads them and gets the result, then puts it back as a order-result.json. Essentially a temp-file system to communicate between the two.
Pipes
Alternatively depending on your setup you could pipe results into php from python with something like the subprocessing module and a php CLI that interfaces with your DB.

How would one make it so that I can send a file to a server and then have my python script manipulate it, and then send it back? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
Sorry for this really vague question but I am just sort of stuck on how to phrase this question so I haven't really been able to find a proper answer just by googling.
Essentially, I have this python script that alters a csv file in a very specific way. Right now it runs fine on my local machine, but I need this to work with the web. Essentially what I want to be possible is for someone to upload their CSV to my site, it would automatically send to my server, my script would see this, manipulate it in the way necessary, and then send it back once it was finished. Does anyone know any methods of doing this that I should look into?
Again, sorry this is so poorly researched sounding but I am just having a lot of trouble properly phrasing it so I haven't been able to find much.
Thanks!
Multiple ways to make it happen.
Use synchronous flow
You would upload the file from the browser, that would be handled by the Flask handler, the handler would process the file and return the updated file in the response. Here you can also use polling to poll the server to see if the processing is done or not using ajax along with polling you can use a loader.
Problem: processing large file, slow internet connection
Use asynchronous flow
You would upload the file from the browser, that would be processed later using some Celery task, other background processor or crontabs that would manipulate the file in the background.
Post manipulation of the file, you can either give an option in the user profile to download the file, send an email attachment or provide download a link, etc.

how to transfer session to another compute node with python? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 days ago.
Improve this question
How to transfer session to another compute node with python in the following case?
case 1: If using kubernete,
case 2: Or using autoscale,
case 3: if using Amazon,
How to transfer session to another compute node with python?
So that program can run forever
Nope, none of those things can transfer a process with all of its in-memory and on-disk state across hosts.
If you’re looking at Kubernetes already, I’d encourage you to design your application so that it doesn’t have any local state. Everything it knows about lives in a database that’s maintained separately (if you’re into AWS, it could be an RDS hosted database or something else). Then you can easily run multiple copies of it (maybe multiple replicas in a Kubernetes ReplicaSet or Deployment) and easily kill one off to restart it somewhere else.
One of the high-end virtualization solutions might be able to do what you’re asking, but keeping a program running forever forever is pretty hard, particularly in a scripting language like Python. (How do you update the program? How do you update the underlying OS, when it needs to reboot to take a kernel update?)

Viewing and managing socket usage in Python [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I am trying to create a utility using Python (3) that, among other things, needs to look at and manage socket usage ON WINDOWS (no, I really don't care if it works on other OS's).
Looking at socket usage: To be clear, I don't want to create a socket or bind to an existing one, I want to be able to get a full list of what sockets are open and what programs have opened them. If you're not sure about what I mean, take a look at TCPView, which does exactly what I'm talking about.
Managing socket usage: Basically, I want to be able to stop programs from connecting from the internet, if necessary. I would assume that the easiest way to do this is to use os.system() to add a new rule to the Windows Firewall, but as that doesn't seem too elegant I'm open to suggestions.
As that's obviously not all the utility will do, I would prefer a library/module of some sort over a 3rd-party program.
You can launch the command "netstat -nabo" to get the list of all active connections & parse the output to get the source, destination, process name & ID. There is no straight forward method to get the active connections in python. You can also get the same information from python invoking iphlpapi. To block or allow a connection windows has command line to add/remove rule from windows firewall.

Using Task Scheduler vs Multithreading [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 8 years ago.
Improve this question
I needed to perform a heavy operation while using a Tkinter GUI. So the GUI would stop responding as soon as the operation began. So, I had two choices(or that's what i think,as I'm new to python & programming as well): MultiThreading or Schtasks .
So, I chose the easier of the two,i.e Schtasks, as I'm working on a deadline(& I dont know much about Multithreading).
What I'm doing is accessing a python file from a different project.
I run batch files which is in this different project(which contains the desired python file that i need to run) to be run by Schtasks
Now the constraint is batch file can access only this python file & not a particular method present in that file(isn't it?) & I need to access only a particular method .
So, my question is:
Is the approach I'm using correct? If not what do you suggest would be better ? Or should I just switch to MultiThreading
Your question opens a huge topic - what you are trying to do is generally not simple and can have large problems which you cannot even foresee if you don't know the topic of multitasking very well. One issue, for example, is synchronizing the access to the file you mention from within different threads or processes or tasks.
However, if you want to start somewhere and just want to write something which separates your GUI code from your computation code, I recommend you start here: http://docs.python.org/2/library/multiprocessing.html .

Categories

Resources